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


C# IServiceCollection.Replace方法代码示例

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


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

示例1: AddControllersAsServices

        public static void AddControllersAsServices(IServiceCollection services, IEnumerable<Type> types)
        {
            var controllerTypeProvider = new StaticControllerTypeProvider();
            foreach (var type in types)
            {
                services.TryAddTransient(type, type);
                controllerTypeProvider.ControllerTypes.Add(type.GetTypeInfo());
            }

            services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
            services.Replace(ServiceDescriptor.Singleton<IControllerTypeProvider>(controllerTypeProvider));
        }
开发者ID:phinq19,项目名称:git_example,代码行数:12,代码来源:ControllersAsServices.cs

示例2: ConfigureModuleServices

        public void ConfigureModuleServices(IServiceCollection services, IConfigurationRoot configuration)
        {
            services.AddTransient<IHttpPipelineDescriptor, MvcPipelineDescriptor>();

            services.AddSingleton<IRouterManager, RouterManager>();
            services.AddTransient<IRouteAnnotation, RouteAnnotation>();
            services.AddTransient<ViewModelHelper, ViewModelHelper>();

            services.AddMvc();

            services.Replace(ServiceDescriptor.Transient<IConfigureOptions<RazorViewEngineOptions>, RazorViewEngineOptionsSetup>());
            services.AddSingleton<IRazorViewEngine, DefaultRazorViewEngine>();
            services.AddSingleton<IControllerTypeRegistrator>(x => x.GetService(typeof(IControllerTypeProvider)) as IControllerTypeRegistrator);
            services.Replace(ServiceDescriptor.Singleton<IControllerTypeProvider, ControllerTypeRegistrator>());
        }
开发者ID:kyrylovych,项目名称:zstu-docs,代码行数:15,代码来源:MvcModule.cs

示例3: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
           
            //services.Replace(ServiceDescriptor.Instance(typeof(IControllerActivator), new Switchb))

            services.AddMvc().AddMvcOptions(
                options =>
                    {
                        options.ModelBinders.Insert(0, new DateTimeBinder());
                    });

            services.Replace(ServiceDescriptor.Transient(typeof(IControllerActivator), typeof(SwitchControllerActivator)));
            services.AddCors(o => o.AddPolicy("AllowAll", builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()));
        }
开发者ID:XYZ-123,项目名称:WeatherApp,代码行数:15,代码来源:Startup.cs

示例4: AddTagHelpersAsServices

        public static void AddTagHelpersAsServices(ApplicationPartManager manager, IServiceCollection services)
        {
            if (manager == null)
            {
                throw new ArgumentNullException(nameof(manager));
            }

            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var feature = new TagHelperFeature();
            manager.PopulateFeature(feature);

            foreach (var type in feature.TagHelpers.Select(t => t.AsType()))
            {
                services.TryAddTransient(type, type);
            }

            services.Replace(ServiceDescriptor.Transient<ITagHelperActivator, ServiceBasedTagHelperActivator>());
            services.Replace(ServiceDescriptor.Transient<ITagHelperTypeResolver, FeatureTagHelperTypeResolver>());
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:23,代码来源:TagHelpersAsServices.cs

示例5: RegisterPublisher

        private void RegisterPublisher(IServiceCollection services)
        {
            var configurationBuilder = new ConfigurationBuilder();
            var path = Path.Combine(configurationBuilder.GetBasePath(), "glimpse.json");

            if (File.Exists(path))
            {
                var configuration = configurationBuilder.AddJsonFile("glimpse.json").Build();
                services.Configure<ResourceOptions>(configuration.GetSection("resources"));

                services.Replace(new ServiceDescriptor(typeof(IMessagePublisher), typeof(HttpMessagePublisher), ServiceLifetime.Transient));
            }

            // TODO: If I reach this line, than Glimpse has no way to send data from point A to B. Should we blow up?
        }
开发者ID:mike-kaufman,项目名称:Glimpse.Prototype,代码行数:15,代码来源:AgentServices.cs

示例6: ConfigureMvc

        private static void ConfigureMvc(IServiceCollection services, IIocResolver iocResolver)
        {
            //See https://github.com/aspnet/Mvc/issues/3936 to know why we added these services.
            services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.TryAddSingleton<IActionContextAccessor, ActionContextAccessor>();
            
            //Use DI to create controllers
            services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());

            //Add feature providers
            var partManager = services.GetSingletonServiceOrNull<ApplicationPartManager>();
            partManager.FeatureProviders.Add(new AbpAppServiceControllerFeatureProvider(iocResolver));

            //Configure JSON serializer
            services.Configure<MvcJsonOptions>(jsonOptions =>
            {
                jsonOptions.SerializerSettings.Converters.Insert(0, new AbpDateTimeConverter());
            });
        }
开发者ID:abdllhbyrktr,项目名称:aspnetboilerplate,代码行数:19,代码来源:AbpServiceCollectionExtensions.cs

示例7: ConfigureServices

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<ApplicationDbContext>(options =>
                    options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));

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

            services.AddMvc();

            // Add application services.
            services.AddTransient<IEmailSender, AuthMessageSender>();
            services.AddTransient<ISmsSender, AuthMessageSender>();

            // Replace HTML generator to supply parsley validation
            services.Replace(ServiceDescriptor.Scoped<IHtmlGenerator, Helpers.CustomHtmlGenerator>());
        }
开发者ID:mburumaxwell,项目名称:Asp.Net5-ParsleyValidation,代码行数:22,代码来源:Startup.cs

示例8: RegisterServices

        public void RegisterServices(IServiceCollection services)
        {
            services.AddOptions();

            //
            // Common
            //
            services.AddSingleton<IServerBroker, DefaultServerBroker>();
            services.AddSingleton<IStorage, InMemoryStorage>();
            services.AddSingleton<IResourceManager, ResourceManager>();

            //
            // Options
            //
            services.AddTransient<IConfigureOptions<GlimpseServerOptions>, GlimpseServerOptionsSetup>();
            services.AddTransient<IExtensionProvider<IAllowClientAccess>, DefaultExtensionProvider<IAllowClientAccess>>();
            services.AddTransient<IExtensionProvider<IAllowAgentAccess>, DefaultExtensionProvider<IAllowAgentAccess>>();
            services.AddTransient<IExtensionProvider<IResource>, DefaultExtensionProvider<IResource>>();
            services.AddTransient<IExtensionProvider<IResourceStartup>, DefaultExtensionProvider<IResourceStartup>>();
            services.AddSingleton<IAllowRemoteProvider, DefaultAllowRemoteProvider>();
            services.AddSingleton<IMetadataProvider, DefaultMetadataProvider>();

            // TODO: switch to TryAdd
            if (!services.Any(s => s.ServiceType == typeof (IMessagePublisher)))
            {
                services.AddSingleton<IMessagePublisher, InProcessPublisher>();
            }

            // TODO: switch to TryAdd
            if (services.Any(s => s.ServiceType == typeof(IResourceOptionsProvider)))
            {
                services.Replace(new ServiceDescriptor(typeof(IResourceOptionsProvider), typeof(DefaultResourceOptionsProvider), ServiceLifetime.Singleton));
            }
            else
            {
                services.AddSingleton<IResourceOptionsProvider, DefaultResourceOptionsProvider>();
            }
        }
开发者ID:mike-kaufman,项目名称:Glimpse.Prototype,代码行数:38,代码来源:ServerServices.cs

示例9: ConfigureTestServices

        public void ConfigureTestServices(IServiceCollection services)
        {
            base.ConfigureServices(services);

            services.Replace<IData>(sp => Mocks.GetData(), ServiceLifetime.Scoped);
        }
开发者ID:ivaylokenov,项目名称:MyTested.AspNetCore.Mvc,代码行数:6,代码来源:TestStartup.cs

示例10: ConfigureServices

 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc();
     services.Replace<IMemoryCache, CustomMemoryCache>(ServiceLifetime.Singleton);
 }
开发者ID:Cream2015,项目名称:MyTested.AspNetCore.Mvc,代码行数:5,代码来源:CachingDataStartup.cs


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