本文整理汇总了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));
}
示例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>());
}
示例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()));
}
示例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>());
}
示例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?
}
示例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());
});
}
示例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>());
}
示例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>();
}
}
示例9: ConfigureTestServices
public void ConfigureTestServices(IServiceCollection services)
{
base.ConfigureServices(services);
services.Replace<IData>(sp => Mocks.GetData(), ServiceLifetime.Scoped);
}
示例10: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Replace<IMemoryCache, CustomMemoryCache>(ServiceLifetime.Singleton);
}