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


C# ContainerBuilder.Populate方法代码示例

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


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

示例1: ConfigureServices

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var bootstrapper = new MyBootstrapper();

            var builder = new ContainerBuilder();

            builder.Populate(bootstrapper);

            builder.Populate(services);

            Container = builder.Build();

            return Container.Resolve<IServiceProvider>();
        }
开发者ID:MinistroFx,项目名称:Ministro,代码行数:14,代码来源:AutofacStartup.cs

示例2: ConfigureServices

        // This method gets called by a runtime.
        // Use this method to add services to the container
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            var builder = new ContainerBuilder();

            builder.RegisterType<ConcreteCacheProvider>().As<ICacheProvider>();
            builder.RegisterType<SerilogLoggerFactory>().As<ILoggerFactory>();

            builder.RegisterType(typeof(ThingyRepository)).Named<IRepository<Thingy>>("repository");

            builder.RegisterGenericDecorator(
                    typeof(CachedRepository<>),
                    typeof(IRepository<>),
                    fromKey: "repository")
                    .Keyed("decorated", typeof(IRepository<>));

            builder.RegisterGenericDecorator(
                    typeof(PerformanceLoggingRepository<>),
                    typeof(IRepository<>),
                    fromKey: "decorated");

            builder.Populate(services);

            var container = builder.Build();

            return container.ResolveOptional<IServiceProvider>();
        }
开发者ID:Stavrakakis,项目名称:Patterns,代码行数:30,代码来源:Startup.cs

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

示例4: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

            services.AddMvc();

            // Create the Autofac container builder.
            var builder = new ContainerBuilder();
            // Add any Autofac modules or registrations.
            builder.RegisterModule(new ServiceModule());
            // Populate the services.
            builder.Populate(services);
            // Build the container.
            var container = builder.Build();
            // Resolve and return the service provider.
            return container.Resolve<IServiceProvider>();
        }
开发者ID:jkurdzieko,项目名称:Pickup,代码行数:28,代码来源:Startup.cs

示例5: Configure

        // Configure is called after ConfigureServices is called.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseServices(services =>
            {
                // We add MVC here instead of in ConfigureServices.
                services.AddMvc();

                // Create the Autofac container builder.
                var builder = new ContainerBuilder();

                // Add any Autofac modules or registrations.
                builder.RegisterModule(new AutofacModule());

                // Populate the services.
                builder.Populate(services);

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

                // Resolve and return the service provider.
                return container.Resolve<IServiceProvider>();
            });

            app.UseStaticFiles();
            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });
            });
        }
开发者ID:kcuzner,项目名称:Autofac,代码行数:34,代码来源:Startup.cs

示例6: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            // Inject services to application.

            var mvcBuilder = services.AddMvc();
            /*mvcBuilder.AddMvcOptions(option =>
            {
                option.OutputFormatters.OfType<JsonOutputFormatter>()
                            .First()
                            .SerializerSettings
                            .ContractResolver = new CamelCasePropertyNamesContractResolver();
            });
            */
            // Create the Autofac container builder.
            var builder = new ContainerBuilder();

            // Add any Autofac modules or registrations.
            builder.RegisterModule(new BusinessModule());
            builder.RegisterModule(new SharedModule());

            // Populate the services.
            builder.Populate(services);

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

            // Resolve and return the service provider.
            return container.Resolve<IServiceProvider>();
        }
开发者ID:onagirnyak,项目名称:OStore,代码行数:34,代码来源:Startup.cs

示例7: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {

            #region Token Bearer
            services.AddJwtAuthentication(Path.Combine(_env.ContentRootPath, "./Security"), "RsaKey.json", "noobs", "http://leadisjourney.fr");
            #endregion

            services.AddNHibernate(Configuration.GetConnectionString("type"), Configuration.GetConnectionString("DefaultConnection"));

            // Add framework services.
            services.AddMvc();
            services.AddCors(option => option.AddPolicy("AllowAll", p =>
            {
                p.AllowAnyOrigin();
                p.AllowCredentials();
                p.AllowAnyMethod();
                p.AllowAnyHeader();
            }));

            // Adding ioc Autofac
            var containerBuilder = new ContainerBuilder();
            containerBuilder.Populate(services);

            containerBuilder.RegisterModule<GlobalRegistration>();
            var container = containerBuilder.Build();
            return container.Resolve<IServiceProvider>();
        }
开发者ID:LeadisJourney,项目名称:Api,代码行数:28,代码来源:Startup.cs

示例8: ConfigureServices

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var builder1 = new ContainerBuilder();
            builder1.RegisterModule<TestModule>();
            builder1.Populate(services);

            var container1 = builder1.Build();

            var nonScopeOptions = container1.Resolve<IServiceProvider>()
                .GetService<Microsoft.Framework.OptionsModel.IOptions<RazorViewEngineOptions>>()
                .Options;

            Console.WriteLine("{0} Options", nonScopeOptions.ViewLocationExpanders.Count);
            Console.WriteLine("");

            var builder2 = new ContainerBuilder();
            builder2.Populate(services);

            var container2 = builder2.Build();

            var scope = container2.BeginLifetimeScope((inner) => {
                inner.RegisterModule<TestModule>();
            }).Resolve<IServiceProvider>();

            var scopeOptions = scope
                .GetService<Microsoft.Framework.OptionsModel.IOptions<RazorViewEngineOptions>>()
                .Options;

            Console.WriteLine("{0} Options", scopeOptions.ViewLocationExpanders.Count);

            return container1.Resolve<IServiceProvider>();
        }
开发者ID:Jetski5822,项目名称:AutofacSample,代码行数:32,代码来源:Startup.cs

示例9: ConfigureServices

        /// <summary>
        /// Sets up the DI container. Loads types dynamically (http://docs.autofac.org/en/latest/register/scanning.html)
        /// </summary>
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            /* TODO: #10
            services.AddCaching();
            services.AddSession();

            services.ConfigureSession(o =>
            {
                o.IdleTimeout = TimeSpan.FromMinutes(5);
            });*/

            services.AddTransient<WopiAuthorizationAttribute>();

            // Autofac resolution
            var builder = new ContainerBuilder();

            // Configuration
            Configuration configuration = new Configuration();
            configuration.AddEnvironmentVariables();
            builder.RegisterInstance(configuration).As<IConfiguration>().SingleInstance();

            // File provider implementation
            var providerAssembly = configuration.Get("WopiFileProviderAssemblyName");
            var assembly = AppDomain.CurrentDomain.Load(new AssemblyName(providerAssembly));
            builder.RegisterAssemblyTypes(assembly).AsImplementedInterfaces();

            builder.Populate(services);
            var container = builder.Build();
            return container.Resolve<IServiceProvider>();
        }
开发者ID:FeodorFitsner,项目名称:WopiHost,代码行数:35,代码来源:Startup.cs

示例10: GetAppContainer

        public static IAppContainer GetAppContainer(IServiceCollection services)
        {
            var builder = new ContainerBuilder();
            builder.RegisterModule<DefaultModule>();
            builder.Populate(services);

            return new AppContainer(builder.Build());
        }
开发者ID:tbehunin,项目名称:kulepool,代码行数:8,代码来源:DependencyResolver.cs

示例11: BuildAndSetResolver

 /// <summary>
 /// 构建服务并设置本地程序平台的Resolver
 /// </summary>
 /// <param name="services">服务映射信息集合</param>
 /// <param name="assemblies">要检索的程序集集合</param>
 /// <returns>服务提供者</returns>
 protected override IServiceProvider BuildAndSetResolver(IServiceCollection services, Assembly[] assemblies)
 {
     ContainerBuilder builder = new ContainerBuilder();
     builder.Populate(services);
     IContainer container = builder.Build();
     LocalIocResolver.Container = container;
     Resolver = container.Resolve<IIocResolver>();
     return Resolver.Resolve<IServiceProvider>();
 }
开发者ID:liumeifu,项目名称:OSky,代码行数:15,代码来源:LocalAutofacIocBuilder.cs

示例12: CreateContainer

        protected override IServiceProvider CreateContainer()
        {
            var builder = new ContainerBuilder();

            builder.Populate(TestServices.DefaultServices());

            IContainer container = builder.Build();
            return container.Resolve<IServiceProvider>();
        }
开发者ID:rgmills,项目名称:Autofac,代码行数:9,代码来源:AutofacContainerTests.cs

示例13: CreateIoCContainer

        private IContainer CreateIoCContainer(IServiceCollection services)
        {
            services.AddTransient<IEmailSender, EmailSender>();

            var containerBuilder = new ContainerBuilder();
            containerBuilder.Populate(services);

            return containerBuilder.Build();           
        }
开发者ID:jonhilt,项目名称:Service-bus-example-site,代码行数:9,代码来源:Startup.cs

示例14: BuildAndSetResolver

 /// <summary>
 /// 构建服务并设置SignalR平台的Resolver
 /// </summary>
 /// <param name="services">服务映射信息集合</param>
 /// <param name="assemblies">要检索的程序集集合</param>
 protected override IServiceProvider BuildAndSetResolver(IServiceCollection services, Assembly[] assemblies)
 {
     ContainerBuilder builder = new ContainerBuilder();
     builder.RegisterHubs().AsSelf().PropertiesAutowired();
     builder.Populate(services);
     IContainer container = builder.Build();
     IDependencyResolver resolver = new AutofacDependencyResolver(container);
     GlobalHost.DependencyResolver = resolver;
     return resolver.Resolve<IServiceProvider>();
 }
开发者ID:donnieyoung,项目名称:osharp,代码行数:15,代码来源:SignalRAutofacIocBuilder.cs

示例15: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        //public void ConfigureServices(IServiceCollection services)
        //{
        //    services.AddMvc();

        //    services.AddSingleton<IService<EmployeeInfo>, EmployeeInfoService>();
        //}

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            var objectBuilder = new ContainerBuilder();
            objectBuilder.RegisterModule<DependencyRegistrationModule>();
            objectBuilder.Populate(services);

            var objectContainer = objectBuilder.Build();
            return objectContainer.Resolve<IServiceProvider>();
        }
开发者ID:dotnetcurry,项目名称:asp.net-mvc6-dependency-injection,代码行数:19,代码来源:Startup.cs


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