本文整理汇总了C#中Autofac.ContainerBuilder.RegisterComponents方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.RegisterComponents方法的具体用法?C# ContainerBuilder.RegisterComponents怎么用?C# ContainerBuilder.RegisterComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autofac.ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder.RegisterComponents方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateContainer
private static IContainer CreateContainer()
{
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterComponents();
var container = containerBuilder.Build();
return container;
}
示例2: Configure
public static IContainer Configure(string authToken, params Assembly[] assemblies)
{
IContainer container = null;
var builder = new ContainerBuilder();
builder.RegisterComponents(assemblies.SelectMany(asm => TryGetTypes(asm)))
// Non-singleton components are registered as per-request.
.ActivatorData.ConfigurationActions.Add((t, rb) =>
{
// We know we have the ComponentAttribute since this is the result of RegisterComponents.
if (!rb.ActivatorData.ImplementationType.GetCustomAttributes(true).OfType<ComponentAttribute>().First().IsSingleton)
rb.InstancePerRequest();
});
builder.Register<IGitHubClient>(c =>
new GitHubClient(
new ProductHeaderValue("OctoHook"),
new InMemoryCredentialStore(
new Credentials(authToken))));
builder.Register<IApiConnection>(c =>
new ApiConnection(c.Resolve<IGitHubClient>().Connection));
container = builder.Build();
return container;
}
示例3: BuildLocator
private static IServiceLocator BuildLocator()
{
var builder = new ContainerBuilder();
builder.RegisterComponents(typeof(IFoo).Assembly);
var container = builder.Build();
return new AutofacServiceLocator(container);
}
示例4: CreateRootContext
private static IComponentContext CreateRootContext()
{
var cb = new ContainerBuilder();
cb.RegisterComponents(typeof(ComponentContext).Assembly);
cb.RegisterType<BindingFactory>()
.AsSelf()
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
var context = new ComponentContext(cb.Build());
return context;
}