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


C# ContainerBuilder.RegisterAssemblyTypes方法代码示例

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


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

示例1: BuildContainer

        static IContainer BuildContainer()
        {
            var builder = new ContainerBuilder();
            var thisAssembly = typeof (Program).GetTypeInfo().Assembly;

            builder.RegisterModule(new LoggingModule());

            builder.RegisterAssemblyTypes(thisAssembly).As<ICommand>().AsSelf();
            builder.RegisterType<CommandLocator>().As<ICommandLocator>();

            builder.RegisterAssemblyTypes(thisAssembly).As<IExporter>().AsSelf();
            builder.RegisterAssemblyTypes(thisAssembly).As<IImporter>().AsSelf();
            builder.RegisterType<ExporterLocator>().As<IExporterLocator>();
            builder.RegisterType<ImporterLocator>().As<IImporterLocator>();

            builder.RegisterType<ReleasePlanBuilder>().As<IReleasePlanBuilder>().SingleInstance();
            builder.RegisterType<PackageVersionResolver>().As<IPackageVersionResolver>().SingleInstance();
            builder.RegisterType<ChannelVersionRuleTester>().As<IChannelVersionRuleTester>().SingleInstance();

            builder.RegisterType<OctopusClientFactory>().As<IOctopusClientFactory>();
            builder.RegisterType<OctopusRepositoryFactory>().As<IOctopusAsyncRepositoryFactory>();

            builder.RegisterType<OctopusPhysicalFileSystem>().As<IOctopusFileSystem>();

            return builder.Build();
        }
开发者ID:OctopusDeploy,项目名称:Octo.exe,代码行数:26,代码来源:Program.cs

示例2: ApplicationContainer

        public ApplicationContainer()
        {
            var builder = new ContainerBuilder();
                //builder.RegisterModule<WhiteboxProfilingModule>();

                //default to InstancePerDependency, i.e., they it will make a new
                //one each time someone asks for one
                builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly());

                builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                    .Where(t => t.GetInterfaces().Contains(typeof(ICommand))).InstancePerLifetimeScope();

                builder.Register(c => LocalizationManager).SingleInstance();

                if (Settings.Default.MruProjects==null)
                {
                    Settings.Default.MruProjects = new MostRecentPathsList();
                }
                builder.RegisterInstance(Settings.Default.MruProjects).SingleInstance();

                //this is to prevent some problems we were getting while waiting for a browser to navigate and being forced to call Application.DoEvents().
                //HtmlThumbnailer & ConfigurationDialog, at least, use this.
                builder.Register(c => new NavigationIsolator()).InstancePerLifetimeScope();

                builder.Register<HtmlThumbNailer>(c => new HtmlThumbNailer(c.Resolve<NavigationIsolator>())).SingleInstance();
                builder.Register<BookThumbNailer>(c => new BookThumbNailer(c.Resolve<HtmlThumbNailer>())).SingleInstance();

                _container = builder.Build();

                Application.ApplicationExit += OnApplicationExit;
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:31,代码来源:ApplicationContainer.cs

示例3: RegisterTypes

        private static void RegisterTypes(ContainerBuilder builder)
        {
            string baseDirectory = HttpContext.Current.Server.MapPath("~/App_Data") + ConfigurationManager.AppSettings["dataFolderName"];

            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            var repositoryAssemblies = Assembly.Load("FileRepository");
            builder.RegisterAssemblyTypes(repositoryAssemblies).AsImplementedInterfaces().WithParameter(new NamedParameter("path", baseDirectory));

            var serviceAssemblies = Assembly.Load("Services");
            builder.RegisterAssemblyTypes(serviceAssemblies).AsImplementedInterfaces();

            var configurationManagerWrapperAssembly = Assembly.Load("ConfigurationManagerWrapper");
            builder.RegisterAssemblyTypes(configurationManagerWrapperAssembly).AsImplementedInterfaces();

            var fileAssembly = Assembly.Load("SystemFileAdapter");
            builder.RegisterAssemblyTypes(fileAssembly).AsImplementedInterfaces();

            //builder.RegisterType<NLogLogger>().As<ILogger>();
            builder.Register(c => new NLogLogger()).As<ILogger>().InstancePerHttpRequest();
            builder.RegisterType<UserHub>();
            builder.RegisterType<TodoHub>();
            //            builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
            builder.RegisterFilterProvider();
        }
开发者ID:kevinrjones,项目名称:DevWeek2013,代码行数:25,代码来源:Global.asax.cs

示例4: RegisterServices

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

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

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

            var usersServicesAssembly = Assembly.GetAssembly(typeof(UsersAdminService));
            builder.RegisterAssemblyTypes(usersServicesAssembly).AsImplementedInterfaces();

            var mediaServicesAssembly = Assembly.GetAssembly(typeof(MediaCategoryService));
            builder.RegisterAssemblyTypes(mediaServicesAssembly).AsImplementedInterfaces();

            var forumServicesAssembly = Assembly.GetAssembly(typeof(ForumPostService));
            builder.RegisterAssemblyTypes(forumServicesAssembly).AsImplementedInterfaces();

            var dropboxCloudStorage = Assembly.GetAssembly(typeof(DropboxCloudStorage));
            builder.RegisterAssemblyTypes(dropboxCloudStorage).AsImplementedInterfaces();

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

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

示例5: 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

示例6: Compose

        private bool Compose()
        {
             var builder = new ContainerBuilder();
             try
             {
                 builder.RegisterAssemblyTypes((typeof(DomainModule).Assembly));
                 builder.RegisterAssemblyTypes((typeof(NetworkModule).Assembly));
                 builder.RegisterAssemblyTypes((typeof(ApplicationModule).Assembly));

                 builder.RegisterModule<DomainModule>();
                 builder.RegisterModule<NetworkModule>();
                 builder.RegisterModule<ApplicationModule>();

                 builder.RegisterType<MessageService>().As<IMessageService>();
                 builder.RegisterType<InterfaceSelectionView>().As<IInterfaceSelectionView>();
                 builder.RegisterType<SharesView>().As<ISharesView>();
                 builder.RegisterType<Query>().As<IQuery>();

                 container = builder.Build();
                 builder = new ContainerBuilder();
                 builder.RegisterInstance<IContainer>(container).SingleInstance();
                 builder.Update(container);
                 return true;
             }
             catch
             {
                 return false;
             }
        }
开发者ID:Kayomani,项目名称:FAP,代码行数:29,代码来源:Program.cs

示例7: Initialize

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

            //Configure for MVC
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

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

            //Register services
            builder.RegisterAssemblyTypes(typeof(PlaylistService).Assembly)
                .Where(t => t.Name.EndsWith("Service"))
                .AsImplementedInterfaces();

            //Configure database
            builder.Register<IDbConnection>(c =>
            {
                var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ConnectionString);

                return conn;

            }).InstancePerRequest();

            //Create the container
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:zmaillard,项目名称:MusicLibrary,代码行数:31,代码来源:IocConfiguration.cs

示例8: RegisterDependencies

        public static void RegisterDependencies()
        {
            //Create the builder
            var builder = new ContainerBuilder();
            
            //Setup common patterns
            builder.RegisterAssemblyTypes()
                   .Where(t => t.Name.EndsWith("Repository"))
                   .AsImplementedInterfaces()
                   .InstancePerHttpRequest();
            builder.RegisterAssemblyTypes()
                   .Where(t => t.Name.EndsWith("Service"))
                   .AsImplementedInterfaces()
                   .InstancePerHttpRequest();
            

            //Register all controllers for the assembly
            builder.RegisterControllers(typeof(MvcApplication).Assembly).InstancePerHttpRequest();


            //Register modules
            builder.RegisterAssemblyModules(typeof(MvcApplication).Assembly);
            builder.RegisterAssemblyModules(typeof(BusinessRegistry).Assembly);
            

            //Inject HTTP Abstractions
            builder.RegisterModule<AutofacWebTypesModule>();
            

            //Set the MVC dependency resolver to use Autofac
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
开发者ID:KalyanArangam,项目名称:SSWTV.DevSuperPower.DI,代码行数:33,代码来源:IoCSimple.cs

示例9: RegisterDependencies

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

            builder.RegisterAssemblyTypes(Assembly.Load("DAL"))
                    .Where(t => t.Name.EndsWith("Repository"))
                    .AsImplementedInterfaces()
                    .InstancePerRequest();

            builder.RegisterAssemblyTypes(Assembly.Load("BO"))
                    .AsImplementedInterfaces()
                    .InstancePerRequest();

            // Note that ASP.NET MVC requests controllers by their concrete types,
            // so registering them As<IController>() is incorrect.
            // Also, if you register controllers manually and choose to specify
            // lifetimes, you must register them as InstancePerDependency() or
            // InstancePerHttpRequest() - ASP.NET MVC will throw an exception if
            // you try to reuse a controller instance for multiple requests.
            builder.RegisterControllers(typeof(MvcApplication).Assembly)
                   .InstancePerRequest();

            builder.RegisterAssemblyModules(typeof(MvcApplication).Assembly);

            builder.RegisterModule<AutofacWebTypesModule>();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(builder.Build()));
        }
开发者ID:ocs72,项目名称:Sandbox,代码行数:28,代码来源:AutofacConfig.cs

示例10: Load

        protected override void Load(ContainerBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }

            foreach (var assemblyContainingMappings in AssembliesWithMappings)
            {
                builder.RegisterAssemblyTypes(assemblyContainingMappings)
                       .AsClosedTypesOf(typeof(ITypeConverter<,>))
                       .AsSelf();

                builder.RegisterAssemblyTypes(assemblyContainingMappings)
                       .AsClosedTypesOf(typeof(ValueResolver<,>))
                       .AsSelf();

                builder.RegisterAssemblyTypes(assemblyContainingMappings)
                       .AsClosedTypesOf(typeof(IMappingAction<,>))
                       .AsSelf();

                builder.RegisterAssemblyTypes(assemblyContainingMappings).Where(
                    t => typeof(Profile).IsAssignableFrom(t))
                    .As<Profile>().SingleInstance();
            }
        }
开发者ID:dejanpalezevic,项目名称:Exercise,代码行数:26,代码来源:AutoMapperModule.cs

示例11: Register

        /// <summary>
        /// Registers all types and sets the resolver for the dependencies
        /// </summary>
        /// <param name="context"></param>
        public static void Register(HttpContextBase context)
        {
            //Set Autofac as dependency resolver
            var builder = new ContainerBuilder();
            builder.RegisterIntegrationServices();
            builder.RegisterAssemblyTypes(Assembly.Load("NearForums.DataAccess"))
                .Where(t => t.Name.EndsWith("DataAccess"))
                .AsImplementedInterfaces()
                .InstancePerDependency();
            builder.RegisterAssemblyTypes(Assembly.Load("NearForums.Services"))
                .Where(t => t.Name.EndsWith("Service"))
                .AsImplementedInterfaces()
                .PropertiesAutowired()
                .InstancePerDependency();
            builder.RegisterNearforumsFilterProvider();
            builder.RegisterControllers(typeof(BaseController).Assembly)
                .PropertiesAutowired();
            builder.RegisterType<DatabaseSettingsRepository>()
                .As<ISettingsRepository>()
                .InstancePerDependency();
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            //Inject configuration dependencies
            SiteConfiguration.SettingsRepository = container.Resolve<ISettingsRepository>();
            SiteConfiguration.PathResolver = context.Server.MapPath;
        }
开发者ID:jorgebay,项目名称:nearforums,代码行数:31,代码来源:DependenciesHelper.cs

示例12: CreateAutofacContainer

        public static ILifetimeScope CreateAutofacContainer(this IServiceCollection services, IConfigurationRoot configuration)
        {
            var builder = new ContainerBuilder();

            // Load web specific dependencies
            builder.RegisterType<AuthMessageSender>()
                .As<IEmailSender>().InstancePerLifetimeScope();
            builder.RegisterAssemblyTypes(typeof(Startup).GetTypeInfo().Assembly).AsImplementedInterfaces();
            builder.RegisterAssemblyTypes(typeof (CartCommandService).GetTypeInfo().Assembly, typeof (ICartCommandService).GetTypeInfo().Assembly)
                .AsImplementedInterfaces();

            var databaseInitializer = new MigrateToLatestVersion(new SampleDataSeeder());
            builder.AddDataOnion(new DbContextConfig(configuration.GetConnectionString("DefaultConnection"), typeof(MusicStoreContext), databaseInitializer));

            // Populate the container with services that were previously registered
            builder.Populate(services);

            builder.RegisterType<BaseRepository<Album, MusicStoreContext>>().As<IRepository<Album>>();
            builder.RegisterType<BaseRepository<Artist, MusicStoreContext>>().As<IRepository<Artist>>();
            builder.RegisterType<BaseRepository<Cart, MusicStoreContext>>().As<IRepository<Cart>>();
            builder.RegisterType<BaseRepository<CartItem, MusicStoreContext>>().As<IRepository<CartItem>>();
            builder.RegisterType<BaseRepository<Genre, MusicStoreContext>>().As<IRepository<Genre>>();
            builder.RegisterType<BaseRepository<Order, MusicStoreContext>>().As<IRepository<Order>>();
            builder.RegisterType<BaseRepository<OrderDetail, MusicStoreContext>>().As<IRepository<OrderDetail>>();

            var container = builder.Build();

            return container;
        }
开发者ID:SSWConsulting,项目名称:enterprise-musicstore-api-aspnet,代码行数:29,代码来源:IoC.cs

示例13: Register

        public static void Register(IAppBuilder app, HttpConfiguration config)
        {
            var aspNetIdentityAssembly = typeof(IMarkerAspNetIdentityInterface).Assembly;
            var cornhouseCoreAssembly = typeof (IMarkerCornhouseCoreInterface).Assembly;
            var executingAssembly = Assembly.GetExecutingAssembly();
            
            var builder = new ContainerBuilder();

            builder.Register(c => InitializeRavenDb.Initialize(aspNetIdentityAssembly)).As<IDocumentStore>().InstancePerLifetimeScope();
            builder.Register(c => c.Resolve<IDocumentStore>().OpenAsyncSession()).As<IAsyncDocumentSession>().InstancePerRequest();
            builder.Register(c => HttpContext.Current.User).InstancePerRequest();

            builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerRequest();
            builder.RegisterType<ApplicationRoleManager>().AsSelf().InstancePerRequest();
            builder.RegisterType<RavenUserStore>().AsSelf().InstancePerRequest();
            builder.RegisterType<RavenRoleStore>().AsSelf().InstancePerRequest();
            

            builder.Register(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
            builder.Register(c => app.GetDataProtectionProvider()).InstancePerRequest();

            builder.RegisterApiControllers(executingAssembly);
            builder.RegisterApiControllers(aspNetIdentityAssembly);

            builder.RegisterAssemblyTypes(executingAssembly).AsImplementedInterfaces().InstancePerRequest();
            builder.RegisterAssemblyTypes(aspNetIdentityAssembly).AsImplementedInterfaces().InstancePerRequest();
            builder.RegisterAssemblyTypes(cornhouseCoreAssembly).AsImplementedInterfaces().InstancePerRequest();
            
            
            var container = builder.Build();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);            
        }
开发者ID:jeremy-holt,项目名称:Cornhouse.Factory-Mutran,代码行数:35,代码来源:AutofacConfig.cs

示例14: Bootstrap

        public static void Bootstrap()
        {
            var builder = new ContainerBuilder();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterAssemblyTypes(typeof (IHandle<>).Assembly)
                .AsImplementedInterfaces();

            builder.RegisterAssemblyTypes(typeof(Denormalizer<>).Assembly)
                .AsImplementedInterfaces();

            //HACK
            builder.RegisterInstance(new Replay.Runner().Rebuild())
                .AsImplementedInterfaces()
                .SingleInstance();

            builder.RegisterModule<EventStoreModule>();
            builder.RegisterType<SignalREventDispatcher>()
                .AsImplementedInterfaces()
                .SingleInstance();

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

            builder.RegisterSource(new ContravariantRegistrationSource());

            var container = builder.Build();

            Command.UseContainer(container.BeginLifetimeScope());
            Denormalizer.UseContainer(container.BeginLifetimeScope());
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
开发者ID:kimsk,项目名称:Kanban,代码行数:32,代码来源:Bootstrapper.cs

示例15: Load

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

              var nancyAssembly = typeof(AppModule).Assembly;

              // Register validators
              builder.RegisterAssemblyTypes(nancyAssembly)
             .AsClosedTypesOf(typeof(IValidator<>))
             .SingleInstance();

              // register all query handlers
              builder.RegisterAssemblyTypes(nancyAssembly)
             .Where(t => t.IsClosedTypeOf(typeof(IHandler<>)))
             .AsImplementedInterfaces();
              builder.RegisterAssemblyTypes(nancyAssembly)
             .Where(t => t.IsClosedTypeOf(typeof(IHandler<,>)))
             .As(t => new KeyedService("queryHandler", t.GetInterfaces().Single(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IHandler<,>))));
              builder.RegisterGenericDecorator(typeof(RequestValidationAwareHandler<,>), typeof(IHandler<,>), "queryHandler");

              // Register other stuff
              builder.RegisterType<NancyIdentityFromContextAssigner>()
             .AsImplementedInterfaces()
             .SingleInstance();
              builder.RegisterType<NancySecurityContextFactory>()
             .AsImplementedInterfaces()
             .SingleInstance();
        }
开发者ID:DavidLievrouw,项目名称:InvoiceGen,代码行数:28,代码来源:NancyModule.cs


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