本文整理汇总了C#中ContainerBuilder.Populate方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.Populate方法的具体用法?C# ContainerBuilder.Populate怎么用?C# ContainerBuilder.Populate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder.Populate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ServiceScopeFactoryIsRegistered
public void ServiceScopeFactoryIsRegistered()
{
var builder = new ContainerBuilder();
builder.Populate(Enumerable.Empty<ServiceDescriptor>());
var container = builder.Build();
container.AssertImplementation<IServiceScopeFactory, AutofacServiceScopeFactory>();
}
示例2: PopulateRegistersServiceScopeFactory
public void PopulateRegistersServiceScopeFactory()
{
var builder = new ContainerBuilder();
builder.Populate(Enumerable.Empty<ServiceDescriptor>());
var container = builder.Build();
container.AssertRegistered<IServiceScopeFactory>();
}
示例3: CorrectServiceProviderIsRegistered
public void CorrectServiceProviderIsRegistered()
{
var builder = new ContainerBuilder();
builder.Populate(Enumerable.Empty<ServiceDescriptor>());
var container = builder.Build();
container.AssertImplementation<IServiceProvider, AutofacServiceProvider>();
}
示例4: CanRegisterGenericService
public void CanRegisterGenericService()
{
var builder = new ContainerBuilder();
var descriptor = new ServiceDescriptor(typeof(IList<>), typeof(List<>), LifecycleKind.Scoped);
builder.Populate(new IServiceDescriptor[] { descriptor });
var container = builder.Build();
container.AssertRegistered<IList<IService>>();
}
示例5: CanRegisterFactoryService
public void CanRegisterFactoryService()
{
var builder = new ContainerBuilder();
var descriptor = new ServiceDescriptor(typeof(IService), sp => new Service(), LifecycleKind.Transient);
builder.Populate(new IServiceDescriptor[] {descriptor});
var container = builder.Build();
container.AssertRegistered<Func<IServiceProvider, IService>>();
}
示例6: CanGenerateFactoryService
public void CanGenerateFactoryService()
{
var builder = new ContainerBuilder();
var descriptor = new ServiceDescriptor(typeof(IService), typeof(Service), ServiceLifetime.Transient);
builder.Populate(new ServiceDescriptor[] {descriptor});
var container = builder.Build();
container.AssertRegistered<Func<IService>>();
}
示例7: CanRegisterSingletonService
public void CanRegisterSingletonService()
{
var builder = new ContainerBuilder();
var descriptor = new ServiceDescriptor(typeof(IService), typeof(Service), LifecycleKind.Singleton);
builder.Populate(new IServiceDescriptor[] {descriptor});
var container = builder.Build();
container.AssertLifetime<IService, RootScopeLifetime>();
container.AssertSharing<IService>(InstanceSharing.Shared);
container.AssertOwnership<IService>(InstanceOwnership.OwnedByLifetimeScope);
}
示例8: CanRegisterTransientService
public void CanRegisterTransientService()
{
var builder = new ContainerBuilder();
var descriptor = new ServiceDescriptor(typeof(IService), typeof(Service), ServiceLifetime.Transient);
builder.Populate(new ServiceDescriptor[] { descriptor });
var container = builder.Build();
container.AssertLifetime<IService, CurrentScopeLifetime>();
container.AssertSharing<IService>(InstanceSharing.None);
container.AssertOwnership<IService>(InstanceOwnership.OwnedByLifetimeScope);
}
示例9: ServiceCollectionConfigurationIsRetainedInRootContainer
public void ServiceCollectionConfigurationIsRetainedInRootContainer()
{
var collection = new ServiceCollection();
collection.AddOptions();
collection.Configure<TestOptions>(options =>
{
options.Value = 5;
});
var builder = new ContainerBuilder();
builder.Populate(collection);
var container = builder.Build();
var resolved = container.Resolve<IOptions<TestOptions>>();
Assert.NotNull(resolved.Value);
Assert.Equal(5, resolved.Value.Value);
}