本文整理汇总了C#中Autofac.ContainerBuilder.Update方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.Update方法的具体用法?C# ContainerBuilder.Update怎么用?C# ContainerBuilder.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Autofac.ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder.Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public void Update(ContainerBuilder cb)
{
if (_rootScope == null)
throw new ZenCoreException("Ядро Zen.Core не получило контейнер при построении. Функционал не доступен.");
cb.Update(_rootScope.ComponentRegistry);
}
示例2: RegisterDependencies
public void RegisterDependencies(Action<ContainerBuilder> build)
{
var cb = new ContainerBuilder();
build?.Invoke(cb);
cb.Update(DependencyContainer);
}
示例3: AddSignalRInjection
private void AddSignalRInjection(IContainer container,IDependencyResolver resolver)
{
var updater = new ContainerBuilder();
updater.RegisterInstance(resolver.Resolve<IConnectionManager>());
updater.Update(container);
}
示例4: ConfigureApplicationContainer
protected override void ConfigureApplicationContainer(ILifetimeScope existingContainer)
{
var builder = new ContainerBuilder();
_tasks.ForEach(task => task.Task.Invoke(builder));
builder.Update(existingContainer.ComponentRegistry);
base.ConfigureApplicationContainer(existingContainer);
}
示例5: ConfigureApplicationContainer
protected override void ConfigureApplicationContainer(ILifetimeScope container)
{
base.ConfigureApplicationContainer(container);
var builder = new ContainerBuilder();
builder.RegisterType<AppSettings>().As<IAppSettings>().SingleInstance();
builder.RegisterType<DummyMailChimpWebhooks>().As<IMailChimpWebhooks>().SingleInstance();
builder.RegisterType<DummyMailgunWebhooks>().As<IMailgunWebhooks>().SingleInstance();
builder.RegisterType<AzureTableStorageTodoService>().As<ITodoService>().SingleInstance();
// Consumers and sagas
builder.RegisterAssemblyTypes(typeof(Bootstrapper).Assembly)
.Where(t => t.Implements<ISaga>() ||
t.Implements<IConsumer>())
.AsSelf();
// Saga repositories
builder.RegisterGeneric(typeof(InMemorySagaRepository<>))
.As(typeof(ISagaRepository<>))
.SingleInstance();
// Service bus
builder.Register(c => ServiceBusFactory.New(sbc =>
{
sbc.ReceiveFrom("loopback://localhost/queue");
sbc.Subscribe(x => x.LoadFrom(container));
})).As<IServiceBus>().SingleInstance();
builder.Update(container.ComponentRegistry);
}
示例6: Main
private static void Main(string[] args)
{
var builder = new ContainerBuilder();
builder.Register(x => x.Resolve<ISessionFactoryBuilder>().Build()).SingleInstance().As<ISessionFactory>();
builder.Register(x => x.Resolve<ISessionFactory>().OpenSession());
builder.Register(x => x.Resolve<ISessionFactory>().OpenStatelessSession());
builder.RegisterType<UnitOfWork>().As<IUnitOfWork>();
builder.RegisterType<BenchSuite>().AsSelf();
builder.RegisterType<SessionHelper>().As<ISessionHelper>();
builder.RegisterType<SqliteSessionFactoryBuilder>().As<ISessionFactoryBuilder>().SingleInstance();
var container = builder.Build();
var suite = container.Resolve<BenchSuite>();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Sqlite");
Console.ResetColor();
suite.Run();
builder = new ContainerBuilder();
builder.RegisterType<MsSqlSessionFactoryBuilder>().As<ISessionFactoryBuilder>().SingleInstance();
builder.Register(x => x.Resolve<ISessionFactoryBuilder>().Build()).SingleInstance().As<ISessionFactory>();
builder.Update(container);
suite = container.Resolve<BenchSuite>();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Mssql");
Console.ResetColor();
suite.Run();
Console.ReadKey();
}
示例7: ConfigureRequestContainer
protected override void ConfigureRequestContainer(Autofac.ILifetimeScope existingContainer)
{
var builder = new ContainerBuilder();
builder.RegisterType<IdeastrikeContext>()
.AsSelf()
.SingleInstance();
builder.RegisterType<IdeaRepository>()
.AsImplementedInterfaces()
.SingleInstance();
builder.RegisterType<ActivityRepository>()
.AsImplementedInterfaces()
.SingleInstance();
builder.RegisterType<FeatureRepository>()
.AsImplementedInterfaces()
.SingleInstance();
builder.RegisterType<SettingsRepository>()
.AsImplementedInterfaces()
.SingleInstance();
builder.RegisterType<UserRepository>()
.AsImplementedInterfaces()
.SingleInstance();
builder.RegisterType<ImageRepository>()
.AsImplementedInterfaces()
.SingleInstance();
builder.Update(existingContainer.ComponentRegistry);
}
示例8: ResolveAutofacDependencies
public static void ResolveAutofacDependencies(this object obj)
{
// Bootstrap
if (Container == null)
{
Container = new Bootstrapper().Bootstrap();
}
if (obj is Page)
{
var builder = new ContainerBuilder();
builder.RegisterInstance(obj).As<Page>();
builder.Update(Container);
}
PropertyInfo[] properties =
obj.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
using (var lifetimeScope = Container.BeginLifetimeScope())
{
foreach (var property in properties.Where(p => p.GetCustomAttributes(typeof(InjectAttribute), false).Any()))
{
object instance = null;
if (!lifetimeScope.TryResolve(property.PropertyType, out instance))
{
throw new InvalidOperationException("Could not resolve type " + property.PropertyType);
}
property.SetValue(obj, instance);
}
}
}
示例9: InitContainer
public static void InitContainer()
{
var builder = new ContainerBuilder();
var container = builder.Build();
var typefinder = new WebAppDomainTypeFinder();
builder = new ContainerBuilder();
builder.RegisterInstance(typefinder).As<ITypeFinder>().SingleInstance();
builder.Update(container);
builder = new ContainerBuilder();
var drtypes = typefinder.FindClassesOfType<IDependencyRegistrar>();
var drInstances = new List<IDependencyRegistrar>();
foreach (var drtype in drtypes)
{
drInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drtype));
}
foreach (var dr in drInstances)
{
dr.Register(builder,typefinder);
}
builder.Update(container);
//将Autofac容器中的实例注册到mvc自带的容器中
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
ContainerManager.RegisterContainer(container);
}
示例10: UseStardustManager
public static void UseStardustManager(this IAppBuilder appBuilder,
ManagerConfiguration managerConfiguration,
ILifetimeScope lifetimeScope)
{
appBuilder.Map(
managerConfiguration.Route,
inner =>
{
var config = new HttpConfiguration
{
DependencyResolver = new AutofacWebApiDependencyResolver(lifetimeScope)
};
config.MapHttpAttributeRoutes();
config.Services.Add(typeof (IExceptionLogger),
new GlobalExceptionLogger());
inner.UseAutofacWebApi(config);
inner.UseWebApi(config);
});
var builder = new ContainerBuilder();
builder.RegisterModule(new ManagerModule(managerConfiguration));
builder.Update(lifetimeScope.ComponentRegistry);
//to start the timers etc
lifetimeScope.Resolve<ManagerController>();
}
示例11: RegisterOperations
private static void RegisterOperations()
{
var newBuilder = new ContainerBuilder();
newBuilder.Register(x => Startup.Container.GetInstance<ISolrOperations<Post>>());
newBuilder.Register(x => Startup.Container.GetInstance<ISolrConnection>());
newBuilder.Update(Big.Box);
}
示例12: ConfigIoc
protected void ConfigIoc()
{
var builder = new ContainerBuilder();
builder.RegisterType<MainWindowViewModel>();
builder.RegisterType<MainWindow>().As<IViewFor<MainWindowViewModel>>();
builder.RegisterInstance(this).As<IScreen>();
var container = builder.Build();
RxApp.ConfigureServiceLocator(
(iface, contract) =>
{
if (contract != null) return container.ResolveNamed(contract, iface);
return container.Resolve(iface);
},
(iface, contract) =>
{
Type constructed = typeof(IEnumerable<>).MakeGenericType(new[] { iface });
if (contract != null) return container.ResolveNamed(contract, constructed) as IEnumerable<object>;
return container.Resolve(constructed) as IEnumerable<object>;
},
(realClass, iface, contract) =>
{
var b = new ContainerBuilder();
if (contract != null)
b.RegisterType(realClass).Named(contract, iface);
else
b.RegisterType(realClass).As(iface);
b.Update(container);
});
}
示例13: Configuration
public void Configuration(IAppBuilder app)
{
// Call our IoC static helper method to start the typical Autofac SignalR setup
var container = IocConfig.RegisterDependencies();
// Get your HubConfiguration. In OWIN, we create one rather than using GlobalHost
var hubConfig = new HubConfiguration();
// Sets the dependency resolver to be autofac.
hubConfig.Resolver = new AutofacDependencyResolver(container);
// OWIN SIGNALR SETUP:
// Register the Autofac middleware FIRST, then the standard SignalR middleware.
app.UseAutofacMiddleware(container);
app.MapSignalR("/signalr", hubConfig);
// There's not a lot of documentation or discussion for owin getting the hubcontext
// Got this from here: https://stackoverflow.com/questions/29783898/owin-signalr-autofac
var builder = new ContainerBuilder();
var connManager = hubConfig.Resolver.Resolve<IConnectionManager>();
builder.RegisterInstance(connManager)
.As<IConnectionManager>()
.SingleInstance();
builder.Update(container);
container.Resolve<IBusControl>().Start();
}
示例14: Application_Start
protected void Application_Start()
{
MvcHandler.DisableMvcResponseHeader = true;
log4net.Config.XmlConfigurator.Configure();
BootStrapper.BootStrap();
var container = BootStrapper.Container;
var builder = new ContainerBuilder();
var config = GlobalConfiguration.Configuration;
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterWebApiFilterProvider(config);
builder.Update(container);
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
AreaRegistration.RegisterAllAreas();
// fluent validation
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
GlobalConfiguration.Configuration.Services.Add(typeof(System.Web.Http.Validation.ModelValidatorProvider), new FluentValidationModelValidatorProvider(new ValidatorFactory()));
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
示例15: ConfigureApplicationContainer
// Perform registration that should have an application lifetime
protected override void ConfigureApplicationContainer(ILifetimeScope existingContainer)
{
_logger.Debug("ConfigureApplicationContainer");
base.ConfigureApplicationContainer(existingContainer);
//When using assembly scanning with IIS applications, you can run into a little trouble depending on how you do the assembly location. (This is one of our FAQs)
//When hosting applications in IIS all assemblies are loaded into the AppDomain when the application first starts, but when the AppDomain is recycled by IIS the assemblies are then only loaded on demand.
//To avoid this issue use the GetReferencedAssemblies() method on System.Web.Compilation.BuildManager to get a list of the referenced assemblies instead:
//var assemblies = System.Web.Compilation.BuildManager.GetReferencedAssemblies().Cast<Assembly>();
var asms = AppDomain.CurrentDomain.GetAssemblies();
//.Where(asm =>asm.GetCustomAttributes().Any(attr => attr.GetType() == typeof(IncludeInNancyAssemblyScanningAttribute)));
var builder = new ContainerBuilder();
//foreach (var asm in asms)
//{
// builder.RegisterAssemblyTypes(asm).Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces();
//}
builder.RegisterModule<Nancy.Demo.Data.DataModule>();
builder.RegisterModule<NancyDemo.Services.ServiceModule>();
builder.RegisterType<Tokenizer>().As<ITokenizer>();
builder.Update(existingContainer.ComponentRegistry);
}