public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration = null) { var describer = new ServiceDescriber(configuration); services.TryAdd(describer.Transient <IHostingEngine, HostingEngine>()); services.TryAdd(describer.Transient <IServerManager, ServerManager>()); services.TryAdd(describer.Transient <IStartupManager, StartupManager>()); services.TryAdd(describer.Transient <IStartupLoaderProvider, StartupLoaderProvider>()); services.TryAdd(describer.Transient <IApplicationBuilderFactory, ApplicationBuilderFactory>()); services.TryAdd(describer.Transient <IHttpContextFactory, HttpContextFactory>()); services.TryAdd(describer.Instance <IApplicationLifetime>(new ApplicationLifetime())); services.AddTypeActivator(configuration); // TODO: Do we expect this to be provide by the runtime eventually? services.AddLogging(configuration); // REVIEW: okay to use existing hosting environment/httpcontext if specified? services.TryAdd(describer.Singleton <IHostingEnvironment, HostingEnvironment>()); // TODO: Remove this once we have IHttpContextAccessor services.AddContextAccessor(configuration); // REVIEW: don't try add because we pull out IEnumerable<IConfigureHostingEnvironment>? services.AddInstance <IConfigureHostingEnvironment>(new ConfigureHostingEnvironment(configuration)); return(services); }
private static IEnumerable <IServiceDescriptor> GetDefaultServicesNonWindows(ServiceDescriber describe) { // If we're not running on Windows, we can't use CNG. // TODO: Replace this with something else. Mono's implementation of the // DPAPI routines don't provide authenticity. return(new[] { describe.Instance <IDataProtectionProvider>(new DpapiDataProtectionProvider(DataProtectionScope.CurrentUser)) }); }
private static IEnumerable <IServiceDescriptor> GetDefaultServicesWindows(ServiceDescriber describe) { List <ServiceDescriptor> descriptors = new List <ServiceDescriptor>(); // Are we running in Azure Web Sites? DirectoryInfo azureWebSitesKeysFolder = TryGetKeysFolderForAzureWebSites(); if (azureWebSitesKeysFolder != null) { // We'll use a null protector at the moment until the // cloud DPAPI service comes online. descriptors.AddRange(new[] { describe.Singleton <IXmlEncryptor, NullXmlEncryptor>(), describe.Instance <IXmlRepository>(new FileSystemXmlRepository(azureWebSitesKeysFolder)) }); } else { // Are we running with the user profile loaded? DirectoryInfo localAppDataKeysFolder = TryGetLocalAppDataKeysFolderForUser(); if (localAppDataKeysFolder != null) { descriptors.AddRange(new[] { describe.Instance <IXmlEncryptor>(new DpapiXmlEncryptor(protectToLocalMachine: false)), describe.Instance <IXmlRepository>(new FileSystemXmlRepository(localAppDataKeysFolder)) }); } else { // If we've reached this point, we have no user profile loaded. RegistryXmlRepository hklmRegXmlRepository = RegistryXmlRepository.GetDefaultRepositoryForHKLMRegistry(); if (hklmRegXmlRepository != null) { // Have WAS and IIS created an auto-gen key folder in the HKLM registry for us? // If so, use it as the repository, and use DPAPI as the key protection mechanism. // We use same-machine DPAPI since we already know no user profile is loaded. descriptors.AddRange(new[] { describe.Instance <IXmlEncryptor>(new DpapiXmlEncryptor(protectToLocalMachine: true)), describe.Instance <IXmlRepository>(hklmRegXmlRepository) }); } else { // Fall back to DPAPI for now return(new[] { describe.Instance <IDataProtectionProvider>(new DpapiDataProtectionProvider(DataProtectionScope.LocalMachine)) }); } } } // We use CNG CBC + HMAC by default. descriptors.AddRange(new[] { describe.Singleton <IAuthenticatedEncryptorConfigurationFactory, CngCbcAuthenticatedEncryptorConfigurationFactory>(), describe.Singleton <ITypeActivator, TypeActivator>(), describe.Singleton <IKeyManager, XmlKeyManager>(), describe.Singleton <IDataProtectionProvider, DefaultDataProtectionProvider>() }); return(descriptors); }
public IServiceCollection AddInstance(Type service, object implementationInstance) { Add(_describe.Instance(service, implementationInstance)); return(this); }