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


C# Container.Populate方法代码示例

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


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

示例1: CreateServiceProvider

        protected override IServiceProvider CreateServiceProvider(IServiceCollection services)
        {
            var container = new Container();

            container.Populate(services);

            return container.GetInstance<IServiceProvider>();
        }
开发者ID:structuremap,项目名称:StructureMap.Microsoft.DependencyInjection,代码行数:8,代码来源:StructureMapContainerTests.cs

示例2: UseBootstrapper

 public static void UseBootstrapper(this IServiceCollection services, params string[] assemblyNames)
 {
     var container = new Container();
     var bootstrapper = new Bootstrapper(container);
     bootstrapper.ScanAssemblies(assemblyNames);
     services.AddInstance(bootstrapper);
     container.Populate(services);
 }
开发者ID:DerAlbertCom,项目名称:DerAlbert.Framework,代码行数:8,代码来源:BoostrapperExtensions.cs

示例3: CreateContainer

        protected override IServiceProvider CreateContainer()
        {
            var container = new Container();

            container.Populate(TestServices.DefaultServices());

            return container.GetInstance<IServiceProvider>();
        }
开发者ID:timplourde,项目名称:structuremap.dnx,代码行数:8,代码来源:StructureMapContainerTests.cs

示例4: ConfigureServices

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // see https://github.com/structuremap/structuremap.dnx

            var container = new Container(c => c.AddRegistry<MyRegistry>());

            container.Populate(services);

            return container.GetInstance<IServiceProvider>();
        }
开发者ID:jeffogata,项目名称:aspnet-di-02-vs,代码行数:10,代码来源:Startup.cs

示例5: PopulatingTheContainerMoreThanOnceThrows

        public void PopulatingTheContainerMoreThanOnceThrows()
        {
            var services = new ServiceCollection();

            services.AddTransient<IFakeService, FakeService>();

            var container = new Container();

            container.Configure(config => config.Populate(services));

            Assert.Throws<InvalidOperationException>(() => container.Populate(services));
        }
开发者ID:structuremap,项目名称:StructureMap.Microsoft.DependencyInjection,代码行数:12,代码来源:StructureMapContainerTests.cs

示例6: ConfigureServices

 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     var container =new Container();
     container.Configure(t =>
     {
         
     });
     container.Populate(services);
     // Add framework services.
     services.AddMvc();
     services.AddCors(o => o.AddPolicy("AllowAll", p => p.AllowAnyOrigin()));
 }
开发者ID:florimm,项目名称:ServiceConnector,代码行数:13,代码来源:Startup.cs

示例7: CreateContainerServiceProvider

        private IServiceProvider CreateContainerServiceProvider(IServiceCollection services)
        {
            var container = new Container(configuration =>
            {
                configuration.For<IConfiguration>().Use(_configuration);
                configuration.For<ApplicationEnvironment>().Use(PlatformServices.Default.Application);

                configuration.AddRegistry<WebRegistry>();
                configuration.AddRegistry<CommonRegistry>();
                configuration.AddRegistry<MembershipRegistry>();
            });
            
            container.Populate(services);

            return container.GetInstance<IServiceProvider>();
        }
开发者ID:tim-cools,项目名称:RealTimeWeb.NET,代码行数:16,代码来源:Startup.cs

示例8: ConfigureServices

        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();

            var container = new Container();
            container.Configure(x =>
            {
                x.Scan(scanning =>
                {
                    scanning.Assembly(Assembly.GetExecutingAssembly());
                    scanning.TheCallingAssembly();
                    scanning.WithDefaultConventions();
                });
            }
            );

            container.Populate(services);
        }
开发者ID:jwilke,项目名称:graphitedata,代码行数:23,代码来源:Startup.cs

示例9: 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 IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMultitenancy<AppTenant, AppTenantResolver>();

            var container = new Container();

            container.Populate(services);

            container.Configure(c =>
            {
                // Application Services
                // c.For<ITenantContainerBuilder<AppTenant>>().Use(() => new AppTenantContainerBuilder(container));
            });

            container.ConfigureTenants<AppTenant>(c =>
            {
                // Tenant Scoped Services
                c.For<IMessageService>().Singleton().Use<MessageService>();
            });

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

示例10: 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 IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var container = new Container();

            // Here we populate the container using the service collection.
            // This will register all services from the collection
            // into the container with the appropriate lifetime.
            container.Populate(services);

            container.Configure(cfg =>
            {
                cfg.For<IServiceScopeFactory>().ContainerScoped().Use<CustomStructureMapServiceScopeFactory>();
                cfg.For<ISessionFactory>().Use<DefaultSessionFactory>();

                cfg.Profile("TestProfile", _ =>
                {
                    _.For<ISessionFactory>().Use<OtherSessionFactory>();
                });
            });

            // Make sure we return an IServiceProvider, 
            // this makes DNX use the StructureMap container.
            return container.GetInstance<IServiceProvider>();
        }
开发者ID:benfoster,项目名称:StructureMapDnxProfileRepro,代码行数:26,代码来源:Startup.cs

示例11: ConfigureServices

        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
           // Add framework serviceProvider.
            services.AddMvc();

            services.AddSingleton<ITaskListRetriever, TaskListRetriever>();
            services.AddSingleton<ITaskRetriever, TaskRetriever>();
            services.AddSingleton<ITasksDAO, TasksDAO>();

            //create handler 

            var subscriberRegistry = new SubscriberRegistry();
            services.AddTransient<IHandleRequests<AddTaskCommand>, AddTaskCommandHandler>();
            subscriberRegistry.Register<AddTaskCommand, AddTaskCommandHandler>();

            //complete handler 
            services.AddTransient<IHandleRequests<CompleteTaskCommand>, CompleteTaskCommandHandler>();
            subscriberRegistry.Register<CompleteTaskCommand, CompleteTaskCommandHandler>();

            //create policies
            var retryPolicy = Policy.Handle<Exception>().WaitAndRetry(new[] { TimeSpan.FromMilliseconds(50), TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(150) });
            var circuitBreakerPolicy = Policy.Handle<Exception>().CircuitBreaker(1, TimeSpan.FromMilliseconds(500));
            var policyRegistry = new PolicyRegistry() { { CommandProcessor.RETRYPOLICY, retryPolicy }, { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy } };

            //create message mappers
            services.AddTransient<IAmAMessageMapper<TaskReminderCommand>, TaskReminderCommandMessageMapper>();
            
            var messagingGatewayConfiguration = RmqGatewayBuilder.With.Uri(new Uri(Configuration["RabbitMQ:Uri"])).Exchange(Configuration["RabbitMQ:Exchange"]).DefaultQueues();

            var gateway = new RmqMessageProducer(messagingGatewayConfiguration);
            IAmAMessageStore<Message> sqlMessageStore = new SqliteMessageStore(new SqliteMessageStoreConfiguration("Data Source = tasks.db", "MessageStores"));

            var container = new Container();
            container.Configure(config =>
            {
                var servicesMessageMapperFactory = new ServicesMessageMapperFactory(container);

                var messageMapperRegistry = new MessageMapperRegistry(servicesMessageMapperFactory)
                    {
                        {typeof(TaskReminderCommand), typeof(TaskReminderCommandMessageMapper)},
                        {typeof(TaskAddedEvent), typeof(TaskAddedEventMapper)},
                        {typeof(TaskEditedEvent), typeof(TaskEditedEventMapper)},
                        {typeof(TaskCompletedEvent), typeof(TaskCompletedEventMapper)},
                        {typeof(TaskReminderSentEvent), typeof(TaskReminderSentEventMapper)}
                    };

                var servicesHandlerFactory = new ServicesHandlerFactory(container);

                var commandProcessor = CommandProcessorBuilder.With()
                    .Handlers(new HandlerConfiguration(subscriberRegistry, servicesHandlerFactory))
                    .Policies(policyRegistry)
                    .TaskQueues(new MessagingConfiguration(sqlMessageStore, gateway, messageMapperRegistry))
                    .RequestContextFactory(new InMemoryRequestContextFactory())
                    .Build();

                config.For<IAmACommandProcessor>().Singleton().Use(() => commandProcessor);

            });
            container.Populate(services);

            return container.GetInstance<IServiceProvider>();
        }
开发者ID:iancooper,项目名称:Paramore,代码行数:62,代码来源:Startup.cs

示例12: 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.AddMvc();
            services.AddSignalR();
            services.AddEntityFrameworkSqlServer(); // .AddEntityFramework().AddSqlServer();
            //services.AddDbContext<ProviderDbContext>(op => op.UseSqlServer(Configuration["Data:POC_DDDContextConnection"]));
            services.AddDbContext<ProviderDbContext>(op =>
                op.UseSqlServer(@"Data Source=.\SQL2016;Initial Catalog=POC_DDD;Integrated Security=False;User ID=srvelicheti;[email protected];MultipleActiveResultSets=true;Trusted_Connection=true;")
                );

            var container = new Container();

            // Here we populate the container using the service collection.
            // This will register all services from the collection
            // into the container with the appropriate lifetime.
            container.Populate(services);

            var bus = NServiceBusBootStrapper.Init(container);
            IocBootstrapper.ConfigureIocContainer(container,bus);
            // Make sure we return an IServiceProvider,
            // this makes Asp.Net Core use the StructureMap container.
            return container.GetInstance<IServiceProvider>();
        }
开发者ID:srivelicheti,项目名称:learning-DDD,代码行数:26,代码来源:Startup.cs

示例13: ConfigureServices

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

            services.AddAuthorization();
            services.ConfigureAuthorization(o => {
                o.AddPolicy(Microsoft.Owin.Security.OAuth.OAuthDefaults.AuthenticationType,
                    new AuthorizationPolicyBuilder().AddAuthenticationSchemes(Microsoft.Owin.Security.OAuth.OAuthDefaults.AuthenticationType)
                    .RequireAuthenticatedUser()                                        
                    .Build());                
            });
            
            var container = new Container();
            //services.AddMvc(options =>
            //{
            //    foreach (var f in options.InputFormatters.OfType<JsonInputFormatter>())
            //    {
            //        f.SerializerSettings.Converters.Add(new IsoDateTimeConverter { DateTimeFormat = "dd-MM-yyyy" });
            //        f.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true });
            //        f.SerializerSettings.Converters.Add(new IocCustomCreationConverter<IHelpContext>(container));
            //    }

            //    //options.ModelBinders.Insert(0, new IoCModelBinder<IHelpContext>(container, options.ModelBinders.ToArray()));
            //});            

            //services.AddMvc()            


            services.AddMvc(options=> {

                foreach (var f in options.InputFormatters.OfType<JsonInputFormatter>())
                {
                    f.SerializerSettings.Converters.Add(new IsoDateTimeConverter { DateTimeFormat = "dd-MM-yyyy" });
                    f.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true });
                    f.SerializerSettings.Converters.Add(new IocCustomCreationConverter<IHelpContext>(container));                    
                }

                foreach(var f in options.OutputFormatters.OfType<JsonOutputFormatter>())
                {
                    var settings = f.SerializerSettings;
                    settings.DateFormatHandling = DateFormatHandling.IsoDateFormat;                    
                    settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                }

                options.ModelBinders.Insert(0, new IoCModelBinder<IHelpContext>(container, options.ModelBinders.ToArray()));
            });                
                       
            container.Configure(x =>
            {
                x.Scan(scanning =>
                {
                    scanning.Assembly(Assembly.GetExecutingAssembly());                
                    scanning.WithDefaultConventions();
                    scanning.Convention<HelperResponseRegistrationConvention>();
                    scanning.AddAllTypesOf<IHelpContextProvider>();
                });


                AutoMapperConfiguration.Configure();
                x.For<IMappingEngine>().Use(() => Mapper.Engine);
                
                //x.AddRegistry<WebsiteRegistry>();
            });

            // Our framework extension point
            container.Populate(services);

          

            return container.GetInstance<IServiceProvider>();
        }
开发者ID:kipwilliams,项目名称:Find.Me,代码行数:71,代码来源:Startup.cs


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