Ejemplo n.º 1
0
        public static IEnumerable <IServiceDescriptor> GetDefaultServices(IConfiguration configuration)
        {
            var describer = new ServiceDescriber(configuration);

            yield return(describer.Transient <IHostingEngine, HostingEngine>());

            yield return(describer.Transient <IServerManager, ServerManager>());

            yield return(describer.Transient <IStartupManager, StartupManager>());

            yield return(describer.Transient <IStartupLoaderProvider, StartupLoaderProvider>());

            yield return(describer.Transient <IBuilderFactory, BuilderFactory>());

            yield return(describer.Transient <IHttpContextFactory, HttpContextFactory>());

            yield return(describer.Transient <ITypeActivator, TypeActivator>());

            yield return(describer.Instance <IApplicationLifetime>(new ApplicationLifetime()));

            // TODO: We expect this to be provide by the runtime eventually.
            yield return(describer.Instance <ILoggerFactory>(new NullLoggerFactory()));

            yield return(new ServiceDescriptor
            {
                ServiceType = typeof(IContextAccessor <>),
                ImplementationType = typeof(ContextAccessor <>),
                Lifecycle = LifecycleKind.Scoped
            });

            if (PlatformHelper.IsMono)
            {
#if NET45
                yield return(describer.Instance <IDataProtectionProvider>(DataProtectionProvider.CreateFromLegacyDpapi()));
#endif
            }
            else
            {
                // The default IDataProtectionProvider is a singleton.
                // Note: DPAPI isn't usable in IIS where the user profile hasn't been loaded, but loading DPAPI
                // is deferred until the first call to Protect / Unprotect. It's up to an IIS-based host to
                // replace this service as part of application initialization.
                yield return(describer.Instance <IDataProtectionProvider>(DataProtectionProvider.CreateFromDpapi()));
            }
        }