当前位置: 首页>>代码示例>>C#>>正文


C# ContainerBuilder.Update方法代码示例

本文整理汇总了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);
 }
开发者ID:holinov,项目名称:Zen.Core,代码行数:7,代码来源:AppCore.cs

示例2: RegisterDependencies

        public void RegisterDependencies(Action<ContainerBuilder> build)
        {
            var cb = new ContainerBuilder();
            build?.Invoke(cb);
            cb.Update(DependencyContainer);

        }
开发者ID:builttoroam,项目名称:applicationstates,代码行数:7,代码来源:RootApplication.cs

示例3: AddSignalRInjection

        private void AddSignalRInjection(IContainer container,IDependencyResolver resolver)
        {
            var updater = new ContainerBuilder();

            updater.RegisterInstance(resolver.Resolve<IConnectionManager>());
            updater.Update(container);
        }
开发者ID:radu-matei,项目名称:signalr-dependency-injection-autofac,代码行数:7,代码来源:Startup.cs

示例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);
 }
开发者ID:rsiwady29,项目名称:FireTower,代码行数:7,代码来源:Bootstrapper.cs

示例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);
        }
开发者ID:rapidexpert,项目名称:SlackCommander,代码行数:31,代码来源:Bootstrapper.cs

示例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();
        }
开发者ID:gobixm,项目名称:learn,代码行数:30,代码来源:Program.cs

示例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);
        }
开发者ID:janode,项目名称:Ideastrike,代码行数:33,代码来源:IdeastrikeBootstrapper.cs

示例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);
				}
			}
		}
开发者ID:JacobAtchley,项目名称:MyVote,代码行数:32,代码来源:AutofacInject.cs

示例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);
        }
开发者ID:shepherds126,项目名称:ShepherdsFramework,代码行数:27,代码来源:InitDependencyContainer.cs

示例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>();
		}
开发者ID:Teleopti,项目名称:Stardust,代码行数:29,代码来源:AppBuilderExtension.cs

示例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);
 }
开发者ID:chandru9279,项目名称:zasz.me,代码行数:7,代码来源:Solr.cs

示例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);
                            });
        }
开发者ID:jaohaohsuan,项目名称:RxUI_QCon,代码行数:35,代码来源:Shell.xaml.cs

示例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();
        }
开发者ID:maldworth,项目名称:SignalRChat-MassTransit,代码行数:28,代码来源:Startup.cs

示例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);
        }
开发者ID:coolworker,项目名称:yue,代码行数:28,代码来源:Global.asax.cs

示例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);
        }
开发者ID:joeyulivecn,项目名称:NancyDemo,代码行数:29,代码来源:CustomBootstrapper.cs


注:本文中的Autofac.ContainerBuilder.Update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。