public static IServiceCollection ImportDnxServices( [NotNull] this IServiceCollection services) { services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Application)); services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.Runtime)); services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoadContextAccessor)); services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.AssemblyLoaderContainer)); services.TryAdd(ServiceDescriptor.Instance(PlatformServices.Default.LibraryManager)); return(services); }
// Internal for testing. internal static void AddRazorViewEngineServices(IServiceCollection services) { if (CompilationServices.Default != null) { services.TryAdd(ServiceDescriptor.Instance(CompilationServices.Default.LibraryExporter)); services.TryAdd(ServiceDescriptor.Instance(CompilationServices.Default.CompilerOptionsProvider)); } services.TryAddEnumerable( ServiceDescriptor.Transient <IConfigureOptions <MvcViewOptions>, MvcRazorMvcViewOptionsSetup>()); services.TryAddEnumerable( ServiceDescriptor.Transient <IConfigureOptions <RazorViewEngineOptions>, RazorViewEngineOptionsSetup>()); services.TryAddSingleton <IRazorViewEngine, RazorViewEngine>(); // Caches view locations that are valid for the lifetime of the application. services.TryAddSingleton <IViewLocationCache, DefaultViewLocationCache>(); services.TryAdd(ServiceDescriptor.Singleton <IChunkTreeCache>(serviceProvider => { var cachedFileProvider = serviceProvider.GetRequiredService <IOptions <RazorViewEngineOptions> >(); return(new DefaultChunkTreeCache(cachedFileProvider.Value.FileProvider)); })); // Caches compilation artifacts across the lifetime of the application. services.TryAddSingleton <ICompilerCacheProvider, DefaultCompilerCacheProvider>(); // This caches compilation related details that are valid across the lifetime of the application. services.TryAddSingleton <ICompilationService, RoslynCompilationService>(); // In the default scenario the following services are singleton by virtue of being initialized as part of // creating the singleton RazorViewEngine instance. services.TryAddTransient <IRazorViewFactory, RazorViewFactory>(); services.TryAddTransient <IRazorPageFactory, VirtualPathRazorPageFactory>(); services.TryAddTransient <IRazorCompilationService, RazorCompilationService>(); services.TryAddTransient <IViewStartProvider, ViewStartProvider>(); services.TryAddTransient <IMvcRazorHost, MvcRazorHost>(); // This caches Razor page activation details that are valid for the lifetime of the application. services.TryAddSingleton <IRazorPageActivator, RazorPageActivator>(); // Only want one ITagHelperActivator so it can cache Type activation information. Types won't conflict. services.TryAddSingleton <ITagHelperActivator, DefaultTagHelperActivator>(); // Consumed by the Cache tag helper to cache results across the lifetime of the application. services.TryAddSingleton <IMemoryCache, MemoryCache>(); }