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


C# ContainerBuilder.RegisterGeneric方法代码示例

本文整理汇总了C#中Autofac.ContainerBuilder.RegisterGeneric方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerBuilder.RegisterGeneric方法的具体用法?C# ContainerBuilder.RegisterGeneric怎么用?C# ContainerBuilder.RegisterGeneric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Autofac.ContainerBuilder的用法示例。


在下文中一共展示了ContainerBuilder.RegisterGeneric方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterGeneric(typeof (BasicRavenRepositoryWithGuid<>))
                   .As(typeof (IRepository<>))
                   .As(typeof (IRepositoryWithGuid<>))
                   .AsImplementedInterfaces();

            builder.RegisterGeneric(typeof (Refrence<>))
                   .PropertiesAutowired()
                   .AsSelf();
        }
开发者ID:holinov,项目名称:ZenEveCalc,代码行数:11,代码来源:RavenRepositoriesModule.cs

示例2: SetAutofacContainer

 private static void SetAutofacContainer()
 {
     var builder = new ContainerBuilder();
     builder.RegisterControllers(Assembly.GetExecutingAssembly());
     builder.RegisterGeneric(typeof (UnitOfWork<>)).As(typeof (IUnitOfWork<>));
     builder.RegisterGeneric(typeof (RepositoryBase<>)).As(typeof (IRepository<>));
     builder.RegisterType(typeof (CategoryService)).As(typeof (ICategoryService)).InstancePerDependency();
     builder.RegisterType(typeof (DepartmentService)).As(typeof (IDepartmentService)).InstancePerDependency();
     IContainer container = builder.Build();
     DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
 }
开发者ID:monica85rodrigues,项目名称:UnitOfWorkWithMultipleDBContext,代码行数:11,代码来源:Bootstrapper.cs

示例3: RegisterCommonComponents

        private void RegisterCommonComponents(ContainerBuilder builder) {
            var mapper = Mapper ?? new MemoizingMappingManager(new AttributesMappingManager());
            builder.RegisterInstance(mapper).As<IReadOnlyMappingManager>();
            // builder.RegisterType<HttpRuntimeCache>().As<ISolrCache>();
            builder.RegisterType<DefaultDocumentVisitor>().As<ISolrDocumentPropertyVisitor>();
            builder.RegisterType<DefaultFieldParser>().As<ISolrFieldParser>();
            builder.RegisterGeneric(typeof (SolrDocumentActivator<>)).As(typeof (ISolrDocumentActivator<>));
            builder.RegisterGeneric(typeof (SolrDocumentResponseParser<>)).As(typeof (ISolrDocumentResponseParser<>));
            builder.RegisterType<DefaultFieldSerializer>().As<ISolrFieldSerializer>();
            builder.RegisterType<DefaultQuerySerializer>().As<ISolrQuerySerializer>();
            builder.RegisterType<DefaultFacetQuerySerializer>().As<ISolrFacetQuerySerializer>();
            builder.RegisterGeneric(typeof(DefaultResponseParser<>)).As(typeof(ISolrAbstractResponseParser<>));

            builder.RegisterType<HeaderResponseParser<string>>().As<ISolrHeaderResponseParser>();
            builder.RegisterType<ExtractResponseParser>().As<ISolrExtractResponseParser>();
            foreach (var p in new[] {
                typeof (MappedPropertiesIsInSolrSchemaRule),
                typeof (RequiredFieldsAreMappedRule),
                typeof (UniqueKeyMatchesMappingRule),
                typeof(MultivaluedMappedToCollectionRule),
            })
			
                builder.RegisterType(p).As<IValidationRule>();
            builder.RegisterType<SolrSchemaParser>().As<ISolrSchemaParser>();				
            builder.RegisterGeneric(typeof(SolrMoreLikeThisHandlerQueryResultsParser<>)).As(typeof(ISolrMoreLikeThisHandlerQueryResultsParser<>));
            builder.RegisterGeneric(typeof(SolrQueryExecuter<>)).As(typeof(ISolrQueryExecuter<>));
            builder.RegisterGeneric(typeof (SolrDocumentSerializer<>)).As(typeof (ISolrDocumentSerializer<>));
            builder.RegisterType<SolrDIHStatusParser>().As<ISolrDIHStatusParser>();
            builder.RegisterType<MappingValidator>().As<IMappingValidator>();
            builder.RegisterType<SolrStatusResponseParser>().As<ISolrStatusResponseParser>();
            builder.RegisterType<SolrCoreAdmin>().As<ISolrCoreAdmin>();
            builder.RegisterType<SolrDictionarySerializer>().As<ISolrDocumentSerializer<Dictionary<string, object>>>();
            builder.RegisterType<SolrDictionaryDocumentResponseParser>().As<ISolrDocumentResponseParser<Dictionary<string, object>>>();
        }
开发者ID:Jo1nes,项目名称:SolrNet,代码行数:34,代码来源:SolrNetModule.cs

示例4: Load

        protected override void Load(ContainerBuilder builder)
        {
            //config
            builder.RegisterType<NHBoxConfig>().As<INHPropertiesProvider>().SingleInstance();

            builder.RegisterType<RepositoryFinder>()
                .PropertiesAutowired()
                .InstancePerDependency();

            //transformations
            builder.RegisterGeneric(typeof (FileBoxTransformation<>)).InstancePerDependency();
            builder.RegisterGeneric(typeof (NHibernateBoxTransformation<,>)).InstancePerDependency();
            builder.RegisterType<BackupsResolver>().InstancePerDependency();
            

            //initialize evaluator
            builder.RegisterType<NHibernateBoxQueryEvaluator>()
                .PropertiesAutowired()
                .SingleInstance();

            builder.RegisterGeneric(typeof(BoxQuery<>))
                .OnActivated(x =>
                {
                    if (BoxedQueryRemoteExtensions.DefaultEvaluator == null)
                        BoxedQueryRemoteExtensions.DefaultEvaluator = x.Context.Resolve<NHibernateBoxQueryEvaluator>().Evaluate;
                });

            base.Load(builder);
        }
开发者ID:ikutsin,项目名称:BinaryAnalysis.Core,代码行数:29,代码来源:BoxQueryModule.cs

示例5: ConfigureContainer

        public static void ConfigureContainer()
        {
            var builder = new ContainerBuilder();
            builder.RegisterControllers(Assembly.GetAssembly(typeof(AutofacConfig)));
            builder.Register(context => NhibernateConfig.GetSessionFactory()).As<ISessionFactory>().SingleInstance();
            
            // Use a session per web request.
            builder.Register(context => context.Resolve<ISessionFactory>().OpenSession())
                .As<ISession>()
                .InstancePerHttpRequest();

            builder.RegisterGeneric(typeof(UserAccountService<>)).AsSelf();
            builder.RegisterType(typeof(SamAuthenticationService<NhUserAccount>))
                .AsSelf()
                .As(typeof(AuthenticationService<NhUserAccount>));
            builder.RegisterGeneric(typeof(MembershipRebootConfiguration<>)).AsSelf();
            builder.RegisterGeneric(typeof(NhRepository<>)).As(typeof(IRepository<>));
            builder.RegisterGeneric(typeof(NhUserAccountRepository<>)).As(typeof(IUserAccountRepository<>));
            builder.RegisterGeneric(typeof(NhGroupRepository<>))
                .As(typeof(IGroupRepository<>));
            builder.RegisterType(typeof(NhGroupRepository<NhGroup>))
               .As(typeof(IGroupQuery));
            builder.Register(
                context => new GroupService<NhGroup>("default", context.Resolve<IGroupRepository<NhGroup>>())).AsSelf();
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:asiFarran,项目名称:BrockAllen.MembershipReboot,代码行数:27,代码来源:AutofacConfig.cs

示例6: Register

        public void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            var zergDataProvider = new ZergDataProvider();
            zergDataProvider.InitDatabase();

            var dataSettingsManager = new DataSettingsManager();
            var dataProviderSettings = dataSettingsManager.LoadSettings();

            //不同数据库对应不同的仓库
            if (dataProviderSettings != null && dataProviderSettings.IsValid())
            {
                builder.Register<IDbContext>(c => new CMSDbContext(dataProviderSettings.RawDataSettings["CMSConnection"])).Named<IDbContext>("CMS").InstancePerRequest();
                builder.Register<IDbContext>(c => new CRMDbContext(dataProviderSettings.RawDataSettings["CRMConnection"])).Named<IDbContext>("CRM").InstancePerRequest();
                builder.Register<IDbContext>(c => new TradingDbContext(dataProviderSettings.RawDataSettings["TradingConnection"])).Named<IDbContext>("Trading").InstancePerRequest();
                builder.Register<IDbContext>(c => new EventDbContext(dataProviderSettings.RawDataSettings["EventConnection"])).Named<IDbContext>("Event").InstancePerRequest();
                builder.Register<IDbContext>(c => new CommunityDbContext(dataProviderSettings.RawDataSettings["CommunityConnection"])).Named<IDbContext>("Community").InstancePerRequest();
            }

            #region 不同的数据库对应不同仓库
            var cmsParameter = new ResolvedParameter((pi, ctx) => pi.Name == "context",
                                            (pi, ctx) => ctx.ResolveNamed<IDbContext>("CMS"));
            var crmParameter = new ResolvedParameter((pi, ctx) => pi.Name == "context",
                                            (pi, ctx) => ctx.ResolveNamed<IDbContext>("CRM"));
            var tradingParameter = new ResolvedParameter((pi, ctx) => pi.Name == "context",
                                            (pi, ctx) => ctx.ResolveNamed<IDbContext>("Trading"));
            var eventPrameter = new ResolvedParameter((pi, ctx) => pi.Name == "context",
                                            (pi, ctx) => ctx.ResolveNamed<IDbContext>("Event"));
            var communityPrameter = new ResolvedParameter((pi, ctx) => pi.Name == "context",
                                            (pi, ctx) => ctx.ResolveNamed<IDbContext>("Community"));

            builder.RegisterGeneric(typeof(CMSRepository<>))
                .WithParameter(cmsParameter)
                .As(typeof(ICMSRepository<>))
                .InstancePerRequest();

            builder.RegisterGeneric(typeof(CRMRepository<>))
                .WithParameter(crmParameter)
                .As(typeof(ICRMRepository<>))
                .InstancePerRequest();

            builder.RegisterGeneric(typeof(TradingRepository<>))
                .WithParameter(tradingParameter)
                .As(typeof(ITradingRepository<>))
                .InstancePerRequest();

            builder.RegisterGeneric(typeof(EventRepository<>))
                .WithParameter(eventPrameter)
                .As(typeof(IEventRepository<>))
                .InstancePerRequest();


            builder.RegisterGeneric(typeof(CommunityRepository<>))
                .WithParameter(communityPrameter)
                .As(typeof(ICommunityRepository<>))
                .InstancePerRequest();
            #endregion
            //            builder.RegisterAssemblyTypes(typeFinder.GetAssemblies().ToArray())
            //                .Where(t =>!String.IsNullOrEmpty(t.Namespace)&& t.Namespace.StartsWith("CMS") && t.Name.Contains("Service"))
            //                .WithParameter(repositeryParameter);
        }
开发者ID:glustful,项目名称:.NetProject,代码行数:60,代码来源:ZergDependencyRegister.cs

示例7: RegisterServices

        private static void RegisterServices(ContainerBuilder builder)
        {
            //var context = ;
            builder.Register(x => new ApplicationDbContext())
                .As<DbContext>()
                .InstancePerRequest();
            builder.Register(x => new HttpCacheService())
                .As<ICacheService>()
                .InstancePerRequest();
            /*builder.Register(x => context)
                .As<IdentityDbContext<ApplicationUser>>()
                .InstancePerRequest();*/
            builder.Register(x => new IdentifierProvider())
                .As<IIdentifierProvider>()
                .InstancePerRequest();

            var servicesAssembly = Assembly.GetAssembly(typeof(ITestsService));
            builder.RegisterAssemblyTypes(servicesAssembly).AsImplementedInterfaces();

            builder.RegisterGeneric(typeof(DbRepository<>))
                .As(typeof(IDbRepository<>))
                .InstancePerRequest();

            builder.RegisterGeneric(typeof(GenericRepository<,>))
                .As(typeof(IDbGenericRepository<,>))
                .InstancePerRequest();

            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                .AssignableTo<BaseController>().PropertiesAutowired();
        }
开发者ID:damy90,项目名称:AvalancheAllerts,代码行数:30,代码来源:AutofacConfig.cs

示例8: Register

        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            Singleton<IDependencyResolver>.Instance = new DependencyResolver();

            string collectionString = "Data Source=.;Initial Catalog=demo;User ID=sa;Password=sa;Trusted_Connection=False;";
            builder.Register<IDbContext>(c => new WaterMoonContext(collectionString)).PerLifeStyle(ComponentLifeStyle.LifetimeScope);
            builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)).PerLifeStyle(ComponentLifeStyle.LifetimeScope);
            builder.RegisterGeneric(typeof(PagedList<>)).As(typeof(IPagedList<>)).PerLifeStyle(ComponentLifeStyle.LifetimeScope);

            builder.RegisterType<DefualtMapping>().As<IMapping>().SingleInstance();

            //注册所有实现IConsumer<>类型的对象
            var consumers = typeFinder.FindClassesOfType(typeof(IConsumer<>)).ToList();
            foreach (var consumer in consumers)
            {
                builder.RegisterType(consumer)
                    .As(consumer.FindInterfaces((type, criteria) =>
                    {
                        var isMatch = type.IsGenericType && ((Type)criteria).IsAssignableFrom(type.GetGenericTypeDefinition());
                        return isMatch;
                    }, typeof(IConsumer<>)))
                    .PerLifeStyle(ComponentLifeStyle.LifetimeScope);
            }
            builder.RegisterType<EventPublisher>().As<IEventPublisher>().SingleInstance();
            builder.RegisterType<SubscriptionService>().As<ISubscriptionService>().SingleInstance();

            builder.RegisterType<DemoService>().As<IDemoService>().PerLifeStyle(ComponentLifeStyle.LifetimeScope);
        }
开发者ID:TelWang,项目名称:WatermoonFramework,代码行数:28,代码来源:DependencyRegistrar.cs

示例9: RegisterServices

        private static void RegisterServices(ContainerBuilder builder)
        {
            builder.Register(x => new ApplicationDbContext())
                .As<DbContext>()
                .InstancePerRequest();

            builder.Register(x => new HttpCacheService())
               .As<ICacheService>()
               .InstancePerRequest();

            builder.Register(x => new HtmlSanitizerAdapter())
               .As<ISanitizer>()
               .InstancePerRequest();

            builder.Register(x => new IdentifierProvider())
               .As<IIdentifierProvider>()
               .InstancePerRequest();

            var servicesAssembly = Assembly.GetAssembly(typeof(IPostsService));
            builder.RegisterAssemblyTypes(servicesAssembly).AsImplementedInterfaces();

            builder.RegisterGeneric(typeof(DbRepository<>)).As(typeof(IDbRepository<>)).InstancePerRequest();
            builder.RegisterGeneric(typeof(UserDbRepository<>)).As(typeof(IUserDbRepository<>)).InstancePerRequest();

            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                .AssignableTo<BaseController>().PropertiesAutowired();
        }
开发者ID:EmilMitev,项目名称:ASP.NET-MVC-Course-Project,代码行数:27,代码来源:AutofacConfig.cs

示例10: Register

        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {


            var asm = AppDomain.CurrentDomain.GetAssemblies();


            builder.RegisterGeneric(typeof(BaseEntityService<>)).As(typeof(IBaseEntityService<>)).InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(BaseEntityWithPictureService<,>)).As(typeof(IBaseEntityWithPictureService<,>)).InstancePerLifetimeScope();

            builder.RegisterType<MobPageHeadBuilder>().As<MobPageHeadBuilder>().InstancePerRequest();

            //register all the implemented services in various mob plugins
            builder.RegisterAssemblyTypes(asm).AsClosedTypesOf(typeof(BaseEntityService<>))
                .AsImplementedInterfaces()
                .InstancePerDependency();

            builder.RegisterAssemblyTypes(asm).AsClosedTypesOf(typeof(BaseEntityWithPictureService<,>))
                .AsImplementedInterfaces()
                .InstancePerDependency();

            //register all the repositories
            builder.RegisterGeneric(typeof(MobRepository<>)).As(typeof(IMobRepository<>))
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>(ContextName))
                        .InstancePerLifetimeScope();

        }
开发者ID:mobsoftware,项目名称:mob.core,代码行数:27,代码来源:BaseMobDependencyRegistrar.cs

示例11: Register

 public void Register(ContainerBuilder builder, SmartConfig config)
 {
     builder.RegisterType<Context.SampleDbContext>().As<DbContext>().InstancePerLifetimeScope();
     builder.RegisterType<Context.OtherDbContext>().As<Context.IOtherDbContext>().InstancePerLifetimeScope();
     builder.RegisterGeneric(typeof(EFRepository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope();
     builder.RegisterGeneric(typeof(EFRepository<,>)).As(typeof(IRepository<,>)).InstancePerLifetimeScope();
 }
开发者ID:DollarRain,项目名称:Smart,代码行数:7,代码来源:DependencyRegistrar.cs

示例12: Register

        public static void Register()
        {
            var builder = new ContainerBuilder();

            //cache manager
            builder.RegisterType<MemoryCacheManager>().As<ICacheManager>().Named<ICacheManager>("static_cache_manager").SingleInstance();
            //builder.RegisterType<PerRequestCacheManager>().As<ICacheManager>().Named<ICacheManager>("per_request_cache_manager").InstancePerLifetimeScope();

            // Since WCF requests does not have an http context we can not use InstancePerHttpRequest(). Instead we can use InstancePerLifetimeScope()
            // which is resolvable for both WCF and http requests. Autofac Wiki says :
            // The default ASP.NET and WCF integrations are set up so that InstancePerLifetimeScope() will attach a component to the current web request or service method call.
            // Register WCF services
            builder.RegisterType<UserService>().InstancePerLifetimeScope();
            builder.RegisterType<GenericCharacteristicService>().InstancePerLifetimeScope();
            builder.RegisterType<DataInfoService>().InstancePerLifetimeScope();

            builder.RegisterType<Config>().InstancePerLifetimeScope();
            builder.RegisterType<WebsiteSearcher>().As<ISearcher>().InstancePerLifetimeScope();
            builder.RegisterType<DebugHelper>().As<IDebugHelper>().SingleInstance();

            // database register
            var dbSettingsManager = new DatabaseSettingsManager();
            var databaseSettings = dbSettingsManager.LoadSettings();
            builder.RegisterType<DatabaseSettingsManager>().InstancePerDependency();
            builder.Register(context => context.Resolve<DatabaseSettingsManager>().LoadSettings()).As<DatabaseSettings>().InstancePerLifetimeScope();
            builder.Register(context => new EfDataProviderManager(context.Resolve<DatabaseSettings>())).As<IDataProviderManager>().InstancePerDependency();
            // register for two types
            builder.Register(context => (IEfDataProvider)context.Resolve<IDataProviderManager>().DataProvider()).As<IDataProvider>().InstancePerDependency();
            builder.Register(context => (IEfDataProvider)context.Resolve<IDataProviderManager>().DataProvider()).As<IEfDataProvider>().InstancePerDependency();

            if (databaseSettings != null && databaseSettings.IsValid())
            {
                //var efDataProviderManager = new EfDataProviderManager(dbSettingsManager.LoadSettings());
                //var dataProvider = (IEfDataProvider)efDataProviderManager.DataProvider();
                //dataProvider.Init();

                builder.Register<IDatabase>(context => new CommerceDbContext(databaseSettings.DataConnectionString)).InstancePerLifetimeScope();
            }
            else
            {
                builder.Register<IDatabase>(context => new CommerceDbContext(dbSettingsManager.LoadSettings().DataConnectionString)).InstancePerLifetimeScope();
            }

            if (!dbSettingsManager.IsFaked)
            {
                builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterGeneric(typeof(FaskeRepository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope();
            }

            //host.EnableDiscovery();
            var container = builder.Build();

            // make AutofacHostFactory.Container equal to EngineContext.Current
            // after it, should not set new container to AutofacHostFactory.Container or EngineContext.Current
            AutofacHostFactory.Container = container;
            EngineContext.Initialize(new AutofacContainerManager(container), new ContainerConfig(), false);
        }
开发者ID:popunit,项目名称:MyEFramework,代码行数:60,代码来源:DependencyRegistrar.cs

示例13: Load

 protected override void Load(ContainerBuilder builder)
 {
     builder.RegisterType<NHibernateQuery>();
     builder.RegisterType<EntityDuplicateChecker>().As<IEntityDuplicateChecker>();
     builder.RegisterGeneric(typeof(NHibernateRepository<>)).As(typeof(INHibernateRepository<>));
     builder.RegisterGeneric(typeof(NHibernateRepositoryWithTypedId<,>)).As(typeof(INHibernateRepositoryWithTypedId<,>));
     builder.RegisterType<DefaultSessionFactoryKeyProvider>().As<ISessionFactoryKeyProvider>();
 }
开发者ID:nucleoid,项目名称:Template-Project,代码行数:8,代码来源:NHibernateModule.cs

示例14: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterGeneric(typeof (BasicNHibernateRepository<>))
                   .As(typeof (IRepository<>));

            builder.RegisterGeneric(typeof(BasicNHibernateRepositoryWithGuid<>))
                   .As(typeof(IRepositoryWithGuid<>));
        }
开发者ID:holinov,项目名称:Zen.Core,代码行数:8,代码来源:NHibernateRepositoriesModule.cs

示例15: SetGenerator

 private static void SetGenerator(ContainerBuilder container)
 {
     container.RegisterType<Generator.Database.LiturgieDatabase>().As<ILiturgieDatabase.ILiturgieDatabase>();
     container.RegisterType<Generator.LiturgieOplosser.LiturgieOplosser>().As<ILiturgieDatabase.ILiturgieLosOp>().WithParameter("defaultSetNameEmpty", Properties.Settings.Default.SetNameEmpty);
     container.RegisterGeneric(typeof(Generator.Database.FileSystem.FileEngine<>)).As(typeof(IDatabase.Engine.IEngine<>));
     container.RegisterGeneric(typeof(Database.EngineManager<>)).As(typeof(IDatabase.IEngineManager<>));
     SetMsPowerpointBuilder(container);
 }
开发者ID:ErikDeRoos,项目名称:koningskerk-beamteam,代码行数:8,代码来源:Bootstrap.cs


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