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); }
// REVIEW: Logging doesn't depend on DI, where should this live? public static IServiceCollection AddLogging(this IServiceCollection services, IConfiguration config = null) { var describe = new ServiceDescriber(config); services.TryAdd(describe.Singleton <ILoggerFactory, LoggerFactory>()); return(services); }
public static IServiceCollection AddTypeActivator([NotNull] this IServiceCollection services, IConfiguration config = null) { var describe = new ServiceDescriber(config); services.TryAdd(describe.Singleton <ITypeActivator, TypeActivator>()); return(services); }
public static IServiceCollection AddSignalR(this IServiceCollection services, IConfiguration configuration, Action <SignalROptions> configureOptions = null) { var describe = new ServiceDescriber(configuration); // Dependencies services.AddOptions(configuration); services.AddDataProtection(configuration); // SignalR services services.TryAdd(describe.Singleton <IMessageBus, MessageBus>()); services.TryAdd(describe.Singleton <IMemoryPool, MemoryPool>()); services.TryAdd(describe.Singleton <IStringMinifier, StringMinifier>()); services.TryAdd(describe.Singleton <ITransportManager, TransportManager>()); services.TryAdd(describe.Singleton <ITransportHeartbeat, TransportHeartbeat>()); services.TryAdd(describe.Singleton <IConnectionManager, ConnectionManager>()); services.TryAdd(describe.Singleton <IAckHandler, AckHandler>()); services.TryAdd(describe.Singleton <AckSubscriber, AckSubscriber>()); services.TryAdd(describe.Singleton <IAssemblyLocator, DefaultAssemblyLocator>()); services.TryAdd(describe.Singleton <IHubManager, DefaultHubManager>()); services.TryAdd(describe.Singleton <IMethodDescriptorProvider, ReflectedMethodDescriptorProvider>()); services.TryAdd(describe.Singleton <IHubDescriptorProvider, ReflectedHubDescriptorProvider>()); services.TryAdd(describe.Singleton <IPerformanceCounterManager, PerformanceCounterManager>()); services.TryAdd(describe.Singleton <JsonSerializer, JsonSerializer>()); services.TryAdd(describe.Singleton <IUserIdProvider, PrincipalUserIdProvider>()); services.TryAdd(describe.Singleton <IParameterResolver, DefaultParameterResolver>()); services.TryAdd(describe.Singleton <IHubActivator, DefaultHubActivator>()); services.TryAdd(describe.Singleton <IJavaScriptProxyGenerator, DefaultJavaScriptProxyGenerator>()); services.TryAdd(describe.Singleton <IJavaScriptMinifier, NullJavaScriptMinifier>()); services.TryAdd(describe.Singleton <IHubRequestParser, HubRequestParser>()); services.TryAdd(describe.Singleton <IHubPipelineInvoker, HubPipeline>()); services.TryAdd(describe.Singleton(typeof(IPersistentConnectionContext <>), typeof(PersistentConnectionContextService <>))); services.TryAdd(describe.Singleton(typeof(IHubContext <>), typeof(HubContextService <>))); services.TryAdd(describe.Singleton(typeof(IHubContext <,>), typeof(HubContextService <,>))); // TODO: Just use the new IDataProtectionProvider abstraction directly here services.TryAdd(describe.Singleton <IProtectedData, DataProtectionProviderProtectedData>()); // Setup the default SignalR options services.TryAdd(describe.Transient <IConfigureOptions <SignalROptions>, SignalROptionsSetup>()); if (configuration != null) { services.Configure <SignalROptions>(configuration); } if (configureOptions != null) { services.ConfigureSignalR(configureOptions); } return(services); }
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 AddSingleton(Type service, Type implementationType) { Add(_describe.Singleton(service, implementationType)); return(this); }