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


C# ContainerBuilder.RegisterType方法代码示例

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


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

示例1: Init

 public void Init() {
     var builder = new ContainerBuilder();
     builder.RegisterType<TokenManager>().As<ITokenManager>();
     builder.RegisterType<TestTokenProvider>().As<ITokenProvider>();
     _container = builder.Build();
     _tokenManager = _container.Resolve<ITokenManager>();
 }
开发者ID:anycall,项目名称:Orchard,代码行数:7,代码来源:TokenManagerTests.cs

示例2: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterModule(new RepositoryModule());

            builder.RegisterType(typeof(SampleArchContext)).As(typeof(DbContext)).InstancePerLifetimeScope();
            builder.RegisterType(typeof(UnitOfWork)).As(typeof(IUnitOfWork)).InstancePerRequest();
        }
开发者ID:syedshah,项目名称:MVCRepository,代码行数:7,代码来源:EFModule.cs

示例3: Main

        static void Main(string[] args)
        {
            var containerBuilder = new ContainerBuilder();

            containerBuilder.RegisterType<Cpu>().As<ICpu>().SingleInstance();
            containerBuilder.RegisterType<Emulator>().As<IEmulator>();
            containerBuilder.RegisterType<Memory>().As<IMemory>().SingleInstance();
            containerBuilder.RegisterType<Ppu>().As<IPpu>();

            var instructionTypes = Assembly.GetExecutingAssembly().GetTypes().Where(f => typeof(IInstruction).IsAssignableFrom(f) && !f.IsAbstract).ToArray();

            containerBuilder.RegisterTypes(instructionTypes)
                .As<IInstruction>();

            var container = containerBuilder.Build();

            var emulator = container.Resolve<IEmulator>();
            var memory = container.Resolve<IMemory>();
            memory.SetCartridge(new Cartridge("../../roms/nestest.nes"));
            emulator.Reset();
            for (;;)
            {
                emulator.Step();
            }
        }
开发者ID:Cyberlane,项目名称:LeetNES,代码行数:25,代码来源:Program.cs

示例4: configureIoC

        private void configureIoC()
        {
            var builder = new ContainerBuilder();
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            builder.Register(ctx => LogManager.GetLogger("trace"))
                .As<Logger>()
                .InstancePerHttpRequest();

            builder.RegisterType<ProcessRunner>()
                .AsImplementedInterfaces()
                .InstancePerDependency()
                ;

            builder.RegisterType<DotProcessor>()
                .AsImplementedInterfaces()
                .SingleInstance()
                ;

            builder.RegisterType<Ansi2HtmlConverter>()
                .AsImplementedInterfaces()
                .InstancePerDependency()
                ;

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:ku3mich,项目名称:dot,代码行数:28,代码来源:Global.asax.cs

示例5: Application_Start

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // Register: create and configure the container
            _container = BootstrapContainer();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(_container));

            var builder = new ContainerBuilder();

            //var configurationRepository =
            //    new ConfigurationRepository.ConfigurationRepository() as IConfigurationRepository;

            //builder.Register(c => configurationRepository).As<IConfigurationRepository>().SingleInstance();

            builder.RegisterType<StashCoreApiConsumer>().As<IStashCoreApiConsumer>();

            builder.RegisterType<PullTrackerRepository>().As<IPullTrackerRepository>();

            builder.RegisterType<RequestProcessFacade>().As<IRequestProcessFacade>();

            IContainer localContainer = builder.Build();

            AutofacHelper.Scope = localContainer;

            _containerProvider = new ContainerProvider(localContainer);
        }
开发者ID:rajasekaran18,项目名称:PullTracker,代码行数:31,代码来源:Global.asax.cs

示例6: SetIocContainer

        private static void SetIocContainer()
        {
            //Implement Autofac

            var configuration = GlobalConfiguration.Configuration;
            var builder = new ContainerBuilder();

            // Register MVC controllers using assembly scanning.
            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            // Register MVC controller and API controller dependencies per request.
            builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerDependency();
            builder.RegisterType<DatabaseFactory>().As<IDatabaseFactory>().InstancePerLifetimeScope();

            // Register service
            builder.RegisterAssemblyTypes(typeof(ProfileService).Assembly)
            .Where(t => t.Name.EndsWith("Service"))
            .AsImplementedInterfaces().InstancePerDependency();

            // Register repository
            builder.RegisterAssemblyTypes(typeof(ProfileRepository).Assembly)
            .Where(t => t.Name.EndsWith("Repository"))
            .AsImplementedInterfaces().InstancePerDependency();

            var container = builder.Build();

            //for MVC Controller Set the dependency resolver implementation.
            var resolverMvc = new AutofacDependencyResolver(container);
            System.Web.Mvc.DependencyResolver.SetResolver(resolverMvc);
        }
开发者ID:raselbappigit,项目名称:properties-management,代码行数:30,代码来源:Bootstrapper.cs

示例7: RegisterHandlersWithAutofac

		public static void RegisterHandlersWithAutofac(ContainerBuilder containerBuilder, IReadOnlyCollection<MessageRegistration> registrations)
		{
			var handlers = registrations.Select(x => x.Handler).Distinct();
			var piplelineHandlers = registrations.Select(x => x.Pipeline).Distinct().SelectMany(x => x).Distinct();

			RegisterLeafHandlers(containerBuilder, handlers);
			RegisterPipelineHandlers(containerBuilder, piplelineHandlers);

			foreach (var registration in registrations)
			{
				if (registration.Dependancies.Any())
				{
					foreach (var dependancy in registration.Dependancies)
					{
						containerBuilder.RegisterType(dependancy).AsSelf();
					}
				}

				if (registration.ScopedDependancies.Any())
				{
					foreach (var dependancy in registration.ScopedDependancies)
					{
						containerBuilder.RegisterType(dependancy).AsSelf().AsImplementedInterfaces().InstancePerLifetimeScope();
					}
				}
			}
		}
开发者ID:Sandboxed-Forks,项目名称:Enexure.MicroBus,代码行数:27,代码来源:ContainerExtensions.cs

示例8: RegisterDefaultServices

        public void RegisterDefaultServices()
        {
            var builder = new ContainerBuilder();
            builder.RegisterInstance(container);
            builder.RegisterType<AutofacServiceLocator>()
                .As<IServiceLocator>()
                .SingleInstance();
            builder.RegisterAssemblyTypes(typeof(IServiceBus).Assembly)
                .AssignableTo<IBusConfigurationAware>()
                .As<IBusConfigurationAware>()
                .SingleInstance();
            builder.RegisterType<DefaultReflection>()
                .As<IReflection>()
                .SingleInstance();
            builder.RegisterType(config.SerializerType)
                .As<IMessageSerializer>()
                .SingleInstance();
            builder.RegisterType<EndpointRouter>()
                .As<IEndpointRouter>()
                .SingleInstance();
            foreach(var module in config.MessageModules)
            {
                builder.RegisterType(module)
                    .Named<string>(module.FullName)
                    .As(typeof(IMessageModule))
                    .SingleInstance();
            }
            builder.Update(container);

            foreach(var busConfigurationAware in container.Resolve<IEnumerable<IBusConfigurationAware>>())
                busConfigurationAware.Configure(config, this);
        }
开发者ID:hjalet,项目名称:rhino-esb,代码行数:32,代码来源:AutofacBuilder.cs

示例9: RegisterServices

        private void RegisterServices(ContainerBuilder builder)
        {
            // repositories
            //override required repository with our custom context
            builder.RegisterType<EfRepository<GroupRule>>()
                .As<IRepository<GroupRule>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>(TAX_GROUPS_CONTEXT_NAME))
                .InstancePerLifetimeScope();

            // repositories
            //override required repository with our custom context
            builder.RegisterType<EfRepository<TaxClass>>()
                .As<IRepository<TaxClass>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>(TAX_GROUPS_CONTEXT_NAME))
                .InstancePerLifetimeScope();

            // repositories
            //override required repository with our custom context
            builder.RegisterType<EfRepository<MemberGroup>>()
                .As<IRepository<MemberGroup>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>(TAX_GROUPS_CONTEXT_NAME))
                .InstancePerLifetimeScope();

            // repositories
            //override required repository with our custom context
            builder.RegisterType<EfRepository<TaxRule>>()
                .As<IRepository<TaxRule>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>(TAX_GROUPS_CONTEXT_NAME))
                .InstancePerLifetimeScope();
            ///////////////////////////////////////////////////////////////////////////////////////////////

            // services
            //builder.RegisterType<GroupDealService>().As<IGroupDealService>().InstancePerLifetimeScope();
            ///////////////////////////////////////////////////////////////////////////////////////////////
        }
开发者ID:mhsohail,项目名称:Livetameion_3.7,代码行数:35,代码来源:DependencyRegistrar.cs

示例10: Load

        protected override void Load(ContainerBuilder builder)
        {
            base.Load(builder);

            builder.RegisterType<ApplicationDatabase>()
                .As<IApplicationDatabase>()
                .SingleInstance();

            builder
                .RegisterType<DatabaseUpgradeDetector>()
                .As<IDatabaseUpgradeDetector>()
                .SingleInstance();

            builder
                .RegisterType<SqlDatabaseProvider>()
                .As<IDatabaseProvider>()
                .Named<IDatabaseProvider>("sql")
                .WithMetadata<IDatabaseProviderMetadata>(c => c.For(m => m.Name, "Sql"));

            builder
                .RegisterType<SqlCeDatabaseProvider>()
                .As<IDatabaseProvider>()
                .Named<IDatabaseProvider>("sqlce")
                .WithMetadata<IDatabaseProviderMetadata>(c => c.For(m => m.Name, "SqlCe"));
        }
开发者ID:nategreenwood,项目名称:nategreenwood.com,代码行数:25,代码来源:DatabaseModule.cs

示例11: TripleTexFacade

        public TripleTexFacade(int syncSystem, string syncPassword, string username, string password)
        {
            _syncSystem = syncSystem;
            _syncPassword = syncPassword;
            _username = username;
            _password = password;

            // Setup IoC and DI
            var builder = new ContainerBuilder();

            // The JsonService keeps the session cookie and has to have one instance per lifetime
            builder.RegisterType<JsonService>().As<IJsonService>().InstancePerLifetimeScope();

            //builder.RegisterAssemblyTypes()
            //       .Where(r => r.Name.EndsWith("Service"))
            //       .AsImplementedInterfaces();

            builder.RegisterType<SyncService>().As<ISyncService>();
            builder.RegisterType<CompanyService>().As<ICompanyService>();
            builder.RegisterType<OrderService>().As<IOrderService>();
            builder.RegisterType<ProductService>().As<IProductService>();

            _container = builder.Build();

            // Login
            _container.Resolve<ISyncService>().Login(_syncSystem, _syncPassword, _username, _password);
        }
开发者ID:nikolaia,项目名称:TripleTexDotNet,代码行数:27,代码来源:TripleTexFacade.cs

示例12: Load

 protected override void Load(ContainerBuilder builder)
 {
     builder.RegisterType<VendingMachineDbContext>()
         .As<DbContext>()
         .AsSelf()
         .InstancePerLifetimeScope();
     builder.RegisterGeneric(typeof (EntityFrameworkUnitOfWork<>))
         .As(typeof (UnitOfWork<>))
         .InstancePerDependency();
     builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
         .Where(x => x.IsClosedTypeOf(typeof (IEntityFactory<,>)))
         .AsImplementedInterfaces()
         .InstancePerDependency();
     builder.RegisterType<CoinsRefundedEventCommitter>()
         .As(typeof (EntityFrameworkTrackedEventCommitter<UserVendingMachineAggregationEntity, CoinsRefundedEvent>))
         .InstancePerDependency();
     builder.RegisterType<GoodsBuyedEventCommitter>()
         .As(typeof (EntityFrameworkTrackedEventCommitter<UserVendingMachineAggregationEntity, GoodsBuyedEvent>))
         .InstancePerDependency();
     //builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
     //    .Where(x => x.IsClosedTypeOf(typeof (ITrackedEventCommitter<,>)))
     //    .As(typeof(EntityFrameworkTrackedEventCommitter<,>))
     //    .AsImplementedInterfaces()
     //    .InstancePerDependency();
 }
开发者ID:DrunkyBard,项目名称:VendingMachine,代码行数:25,代码来源:TypeRegistrationModule.cs

示例13: Load

        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<ConfigManager>().As<IConfigManager>()
                .WithParameter(new NamedParameter("navigation", this.Navigation));

            builder.RegisterType<SecurityManager>().As<ISecurityManager>();
        }
开发者ID:perceptal,项目名称:starter.net,代码行数:7,代码来源:CoreWebModule.cs

示例14: SetAutofacContainer

        private static void SetAutofacContainer(string dbConnectionString)
        {
            var builder = new ContainerBuilder();

            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterType<DefaultValidationBus>().As<IValidationBus>().InstancePerHttpRequest();
            builder.RegisterAssemblyTypes(Assembly.Load("Utilities")).AsImplementedInterfaces().InstancePerHttpRequest();

            builder.RegisterType<ScrabbleClubContext>().WithParameter("connectionStringName", dbConnectionString).InstancePerHttpRequest();

            var infrastructureDataAccessLayerAssembly = Assembly.Load("DataAccess");
            builder.RegisterAssemblyTypes(infrastructureDataAccessLayerAssembly)
                   .Where(t => t.Name.EndsWith("Repository"))
                   .AsImplementedInterfaces().InstancePerHttpRequest();

            var domainLayerAssembly = Assembly.Load("Domain");
            builder.RegisterAssemblyTypes(domainLayerAssembly)
                   .Where(t => t.Name.EndsWith("Service"))
                   .AsImplementedInterfaces()
                   .InstancePerHttpRequest();

            var applicationLayerAssembly = Assembly.Load("Application");
            builder.RegisterAssemblyTypes(applicationLayerAssembly)
                   .AsClosedTypesOf(typeof (IValidationHandler<>)).InstancePerHttpRequest();
            builder.RegisterAssemblyTypes(applicationLayerAssembly)
                   .Where(t => t.Name.EndsWith("Service"))
                   .AsImplementedInterfaces()
                   .InstancePerHttpRequest();

            builder.RegisterFilterProvider();
            IContainer container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:slask,项目名称:MVCArchitectureTemplate,代码行数:33,代码来源:Bootstrapper.cs

示例15: RegisterServices

        private static IContainer RegisterServices(ContainerBuilder builder)
        {

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            // EF DbContext
            builder.RegisterType<EntitiesContext>()
                   .As<DbContext>()
                   .InstancePerApiRequest();

            // Register repositories by using Autofac's OpenGenerics feature
            // More info: http://code.google.com/p/autofac/wiki/OpenGenerics
            builder.RegisterGeneric(typeof(EntityRepository<>))
                   .As(typeof(IEntityRepository<>))
                   .InstancePerApiRequest();

            // Services
            builder.RegisterType<CryptoService>()
                .As<ICryptoService>()
                .InstancePerApiRequest();

            builder.RegisterType<MembershipService>()
                .As<IMembershipService>()
                .InstancePerApiRequest();

            builder.RegisterType<ShipmentService>()
                .As<IShipmentService>()
                .InstancePerApiRequest();

            return builder.Build();
        }
开发者ID:NikolayKostadinov,项目名称:PingYourPackage,代码行数:31,代码来源:AutofacConfig.cs


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