本文整理汇总了C#中ServiceProvider.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceProvider.Add方法的具体用法?C# ServiceProvider.Add怎么用?C# ServiceProvider.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceProvider
的用法示例。
在下文中一共展示了ServiceProvider.Add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAddDuplicateService2
public void TestAddDuplicateService2()
{
ServiceProvider provider = new ServiceProvider();
provider.Add<ILog>(new ServiceCreatorCallback<ILog>(ServiceRequested));
ILog log1 = new NoLog();
provider.Add<ILog>(log1);
}
示例2: TestAddDuplicateService1
public void TestAddDuplicateService1()
{
ServiceProvider provider = new ServiceProvider();
ILog log1 = new NoLog();
ILog log2 = new NoLog();
provider.Add<ILog>(log1);
provider.Add<ILog>(log2);
}
示例3: TestServiceCreatorCallback
public void TestServiceCreatorCallback()
{
ServiceProvider provider = new ServiceProvider();
provider.Add<ILog>(new ServiceCreatorCallback<ILog>(ServiceRequested));
ILog log = provider.Get<ILog>();
Assert.IsNotNull(log);
}
示例4: Create
/// <summary>
/// Create a default ServiceProvider with the given settings.
/// </summary>
/// <param name="settings"></param>
/// <param name="configuration"></param>
/// <returns></returns>
public static IServiceProvider Create(IDictionary<string, string> settings, Action<ServiceProvider> configuration)
{
if (settings == null)
{
throw new ArgumentNullException("settings");
}
if (configuration == null)
{
throw new ArgumentNullException("configuration");
}
var services = new ServiceProvider();
DoCallback(settings, (service, implementation) => services.Add(service, implementation));
configuration(services);
return services;
}
示例5: AddCodeGenerationServices
private static void AddCodeGenerationServices(ServiceProvider serviceProvider)
{
if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}
serviceProvider.Add(typeof(IApplicationEnvironment), PlatformServices.Default.Application);
serviceProvider.Add(typeof(IRuntimeEnvironment), PlatformServices.Default.Runtime);
serviceProvider.Add(typeof(IAssemblyLoadContextAccessor), PlatformServices.Default.AssemblyLoadContextAccessor);
serviceProvider.Add(typeof(IAssemblyLoaderContainer), PlatformServices.Default.AssemblyLoaderContainer);
serviceProvider.Add(typeof(ILibraryManager), PlatformServices.Default.LibraryManager);
serviceProvider.Add(typeof(ILibraryExporter), CompilationServices.Default.LibraryExporter);
serviceProvider.Add(typeof(ICompilerOptionsProvider), CompilationServices.Default.CompilerOptionsProvider);
//Ordering of services is important here
serviceProvider.Add(typeof(ILogger), new ConsoleLogger());
serviceProvider.Add(typeof(IFilesLocator), new FilesLocator());
serviceProvider.AddServiceWithDependencies<ICodeGeneratorAssemblyProvider, DefaultCodeGeneratorAssemblyProvider>();
serviceProvider.AddServiceWithDependencies<ICodeGeneratorLocator, CodeGeneratorsLocator>();
serviceProvider.AddServiceWithDependencies<ICompilationService, RoslynCompilationService>();
serviceProvider.AddServiceWithDependencies<ITemplating, RazorTemplating>();
serviceProvider.AddServiceWithDependencies<IPackageInstaller, PackageInstaller>();
serviceProvider.AddServiceWithDependencies<IModelTypesLocator, ModelTypesLocator>();
serviceProvider.AddServiceWithDependencies<ICodeGeneratorActionsService, CodeGeneratorActionsService>();
serviceProvider.AddServiceWithDependencies<IDbContextEditorServices, DbContextEditorServices>();
serviceProvider.AddServiceWithDependencies<IEntityFrameworkService, EntityFrameworkServices>();
}
示例6: Create
public static ServiceProvider Create()
{
var services = new ServiceProvider();
DoCallback((service, implementation) => services.Add(service, implementation));
return services;
}