本文整理汇总了C#中this.AddSingleton方法的典型用法代码示例。如果您正苦于以下问题:C# this.AddSingleton方法的具体用法?C# this.AddSingleton怎么用?C# this.AddSingleton使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类this
的用法示例。
在下文中一共展示了this.AddSingleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddWebFileSystems
public static IServiceCollection AddWebFileSystems(this IServiceCollection services)
{
services.AddSingleton<IClientFolder, WebSiteFolder>();
services.AddSingleton<IVirtualPathProvider, DefaultVirtualPathProvider>();
return services;
}
示例2: AddDD4T
public static void AddDD4T(this IServiceCollection services)
{
//var configuration = new Configuration()
// .AddJsonFile("config.json")
// .AddEnvironmentVariables();
//var config = JsonConvert.DeserializeObject<DD4TConfiguration>()
//var x = configuration.GetSubKey("DD4TAppSettings");
services.AddSingleton<IPublicationResolver, DefaultPublicationResolver>();
services.AddSingleton<ILogger, NullLogger>();
services.AddSingleton<ICacheAgent, NullCacheAgent>();
services.AddSingleton<IDD4TConfiguration, DD4TConfiguration>();
//services.Configure<DD4TConfiguration>(configuration.GetSubKey("DD4TAppSettings"));
services.AddTransient<ISerializerService, JSONSerializerService>();
services.AddTransient<IPageProvider, TridionPageProvider>();
services.AddTransient<IComponentPresentationProvider, ComponentPresentationProvider>();
services.AddTransient<ILinkProvider, LinkProvider>();
services.AddTransient<IFactoriesFacade, FactoriesFacade>();
services.AddTransient<IPageFactory, PageFactory>();
services.AddTransient<IComponentFactory, ComponentFactory>();
services.AddTransient<IComponentPresentationFactory, ComponentPresentationFactory>();
services.AddTransient<IBinaryFactory, BinaryFactory>();
services.AddTransient<ILinkFactory, LinkFactory>();
services.AddTransient<IFactoriesFacade, FactoriesFacade>();
}
示例3: ConfigureAuthorization
public static void ConfigureAuthorization(this IServiceCollection services)
{
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<SecurityDbContext>()
.AddDefaultTokenProviders();
services.AddAuthorization(options =>
{
options.AddPolicy("RequireClimePolicyTest", policy =>
{
policy.RequireClaim("RequireClimePolicyTest");
});
options.AddPolicy("RequireRolePolicyTest", policy =>
{
policy.RequireRole("RequireRolePolicyTest");
});
options.AddPolicy("RequirementBasedPolicyTest", policy =>
{
policy.AddRequirements(new TestRequirement(preSatisfied: true));
});
});
services.AddSingleton<IAuthorizationHandler, ResourceBasedAuthorizationHandler>();
services.AddSingleton<IAuthorizationHandler, RequirementBasedAuthorizationHandler>();
}
示例4: AddFileSystems
public static IServiceCollection AddFileSystems(this IServiceCollection services)
{
services.AddSingleton<IAppDataFolderRoot, AppDataFolderRoot>();
services.AddSingleton<IAppDataFolder, PhysicalAppDataFolder>();
return services;
}
示例5: AddBrickPile
public static void AddBrickPile(this IServiceCollection services)
{
_serviceProvider = services.BuildServiceProvider();
services.AddMvc().ConfigureApplicationPartManager(manager =>
{
var feature = new ControllerFeature();
manager.PopulateFeature(feature);
services.AddSingleton<IControllerMapper>(new ControllerMapper(feature));
});
services.AddRouting(options =>
{
options.AppendTrailingSlash = true;
options.LowercaseUrls = true;
});
services.Configure<MvcOptions>(options =>
{
options.ModelBinderProviders.Insert(0, new DefaultModelBinderProvider(DocumentStore));
options.Filters.Add(typeof(PublishedFilterAttribute), 1);
options.Filters.Add(typeof(AuthorizeFilterAttribute), 2);
});
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton(DocumentStore);
services.AddTransient<IRouteResolverTrie>(provider => new RouteResolverTrie(provider.GetService<IDocumentStore>()));
services.AddTransient<IBricsContextAccessor>(provider => new BricsContextAccessor(provider.GetService<IHttpContextAccessor>(), provider.GetService<IDocumentStore>()));
}
示例6: AddOnlineTvDatabase
public static IServiceCollection AddOnlineTvDatabase(this IServiceCollection services)
{
services.AddSingleton<IOnlineTvDatabase, OnlineTvDatabaseClient>();
services.AddScoped<IHttpClient, HttpClient>();
services.AddSingleton<IObjectUrlFactory, ObjectUrlFactory>();
services.AddScoped<IObjectUrlBuilder<GetSeriesInput>, GetSeriesUrlBuilder>();
return services;
}
示例7: AddUmbracoCore
public static IServiceCollection AddUmbracoCore(this IServiceCollection services)
{
services.AddSingleton<IUmbracoAssemblyProvider, ReferencedAssemblyProvider>();
services.AddSingleton<TypeHelper>();
services.AddSingleton<ITypeFinder, TypeFinder>();
return services;
}
示例8: AddOgnAnalyserServices
public static IServiceCollection AddOgnAnalyserServices(this IServiceCollection sp, OGNClientSettings settings)
{
sp.AddSingleton<APRSClient>();
sp.AddSingleton<AircraftTrackAnalyser>();
sp.AddSingleton<OGNClientSettings>(r => settings);
return sp;
}
示例9: AddDomainEntity
public static IServiceCollection AddDomainEntity(this IServiceCollection service)
{
service.AddSingleton<IRepository<Item>, Repository<Item>>();
service.AddSingleton<IRepository<ItemType>, Repository<ItemType>>();
service.AddSingleton<IRepository<Menu>, Repository<Menu>>();
service.AddSingleton<IRepository<ItemTrace>, Repository<ItemTrace>>();
return service;
}
示例10: AddOpenIdConnectServer
public static IServiceCollection AddOpenIdConnectServer(this IServiceCollection services)
{
services.AddWebEncoders();
services.AddSingleton<HtmlEncoder>();
services.AddSingleton<UrlEncoder>();
return services;
}
示例11: AddLog4NetServices
/// <summary>
/// 添加Log4Net日志功能相关映射信息
/// </summary>
public static void AddLog4NetServices(this IServiceCollection services)
{
if (OSharpConfig.LoggingConfigReseter == null)
{
OSharpConfig.LoggingConfigReseter = new Log4NetLoggingConfigReseter();
}
services.AddSingleton<IBasicLoggingInitializer, Log4NetLoggingInitializer>();
services.AddSingleton<Log4NetLoggerAdapter>();
}
示例12: UseSmtp4dev
public static void UseSmtp4dev(this IServiceCollection services)
{
SettingsStore settingsStore = new SettingsStore();
services.AddSingleton<ISettingsStore>(settingsStore);
MessageStore messageStore = new MessageStore();
services.AddSingleton<IMessageStore>(messageStore);
services.AddTransient<ISmtp4devEngine, Smtp4devEngine>();
}
示例13: AddJsonLocalization
public static IServiceCollection AddJsonLocalization(this IServiceCollection services, Action<JsonStringLocalizerOptions> options)
{
if (options != null)
{
services.Configure(options);
}
services.AddSingleton<IStringLocalizerFactory, JsonStringLocalizerFactory>();
services.AddSingleton(typeof(IStringLocalizer<>), typeof(JsonStringLocalizer<>));
return services;
}
开发者ID:folkelib,项目名称:Folke.Localization.Json,代码行数:10,代码来源:JsonLocalizationServiceCollectionExtensions.cs
示例14: AddExternalTemplates
/// <summary>
/// Adds ExternalTemplates services.
/// </summary>
public static IServiceCollection AddExternalTemplates(this IServiceCollection services)
{
services.AddSingleton<IGeneratorOptions, GeneratorOptions>(
provider => provider.GetRequiredService<IOptions<GeneratorOptions>>().Value);
services.AddSingleton<IFilesProvider, FilesProvider>();
services.AddSingleton<ICoreGenerator, CoreGenerator>();
services.AddSingleton<IGenerator, Generator>();
return services;
}
示例15: AddContextAccessor
public static IServiceCollection AddContextAccessor(this IServiceCollection self)
{
if (self.Count(x => x.ServiceType == typeof(IHttpContextAccessor)) == 0)
self.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
if (self.Count(x => x.ServiceType == typeof(IActionContextAccessor)) == 0)
self.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
return self;
}