public static IEnumerable <IServiceDescriptor> DefaultServices()
        {
            var describer = new ServiceDescriber();

            yield return(describer.Transient <IFakeService, FakeService>());

            yield return(describer.Transient <IFakeMultipleService, FakeOneMultipleService>());

            yield return(describer.Transient <IFakeMultipleService, FakeTwoMultipleService>());

            yield return(describer.Transient <IFakeOuterService, FakeOuterService>());

            yield return(describer.Instance <IFakeServiceInstance>(new FakeService()
            {
                Message = "Instance"
            }));

            yield return(describer.Scoped <IFakeScopedService, FakeService>());

            yield return(describer.Singleton <IFakeSingletonService, FakeService>());

            yield return(describer.Transient <IFakeFallbackService, FakeService>());

            yield return(describer.Transient <IDependOnNonexistentService, DependOnNonexistentService>());

            yield return(describer.Describe(
                             typeof(IFakeOpenGenericService <string>),
                             typeof(FakeService),
                             lifecycle: LifecycleKind.Transient));

            yield return(describer.Describe(
                             typeof(IFakeOpenGenericService <>),
                             typeof(FakeOpenGenericService <>),
                             lifecycle: LifecycleKind.Transient));

            yield return(describer.Transient <IFactoryService>(provider =>
            {
                var fakeService = provider.GetService <IFakeService>();
                return new TransientFactoryService
                {
                    FakeService = fakeService,
                    Value = 42
                };
            }));

            yield return(describer.Scoped <ScopedFactoryService>(provider =>
            {
                var fakeService = provider.GetService <IFakeService>();
                return new ScopedFactoryService
                {
                    FakeService = fakeService,
                };
            }));

            yield return(describer.Transient <ServiceAcceptingFactoryService, ServiceAcceptingFactoryService>());
        }
Esempio n. 2
0
        private void RegisterBluePrintItem(List <SmartServiceDescriptor> smartServiceDescriptors, List <EventSubscriptionDescriptor> eventSubs, Dictionary <Type, MethodInfo[]> methodsCache, HashSet <string> flags, ShellBlueprintDependencyItem item, Type interfaceType)
        {
            SmartServiceDescriptor descriptor = null;

            if (typeof(ISingletonDependency).GetTypeInfo().IsAssignableFrom(interfaceType))
            {
                eventSubs.AddRange(CreateDescriptor(methodsCache, flags, interfaceType, item.Type, ServiceLifetime.Singleton));
                descriptor = ServiceDescriber.Singleton(interfaceType, item.Type, SmartOptions.Append);
                item.Interfaces.Add(new Tuple <Type, ServiceLifetime>(interfaceType, ServiceLifetime.Singleton));
            }
            else if (typeof(ITransientDependency).GetTypeInfo().IsAssignableFrom(interfaceType))
            {
                eventSubs.AddRange(CreateDescriptor(methodsCache, flags, interfaceType, item.Type, ServiceLifetime.Transient));
                descriptor = ServiceDescriber.Transient(interfaceType, item.Type, SmartOptions.Append);
                item.Interfaces.Add(new Tuple <Type, ServiceLifetime>(interfaceType, ServiceLifetime.Transient));
            }
            else
            {
                eventSubs.AddRange(CreateDescriptor(methodsCache, flags, interfaceType, item.Type, ServiceLifetime.Scoped));
                descriptor = ServiceDescriber.Scoped(interfaceType, item.Type, SmartOptions.Append);
                item.Interfaces.Add(new Tuple <Type, ServiceLifetime>(interfaceType, ServiceLifetime.Scoped));
            }

            if (descriptor != null)
            {
                descriptor = this.OnDependencyRegistering(descriptor);
                smartServiceDescriptors.Add(descriptor);
            }
        }
        public static SchubertServicesBuilder AddEntityFrameworkFeature(this SchubertServicesBuilder builder, Action <DbBuilder> setup = null)
        {
            DbOptions options = new DbOptions();

            if (builder.AddedModules.Add(_module))
            {
                var configuration = builder.Configuration.GetSection("Schubert:Data") as IConfiguration ?? new ConfigurationBuilder().Build();
                builder.ServiceCollection.Configure <DbOptions>(configuration);

                var schubertDataSetup = new ConfigureFromConfigurationOptions <DbOptions>(configuration);
                schubertDataSetup.Configure(options);
            }


            DbBuilder dbBuilder = new DbBuilder();

            if (setup != null)
            {
                setup(dbBuilder);
                if (dbBuilder.Setup != null)
                {
                    dbBuilder.Setup(options);
                    builder.ServiceCollection.Configure(dbBuilder.Setup);
                }
            }

            options.DbContextSettings = dbBuilder.DbSettings;
            builder.ServiceCollection.Configure <DbOptions>(dbOp =>
            {
                dbOp.DbContextSettings.AddRange(dbBuilder.DbSettings, true);
            });
            _dbConnectionMappings.AddRange(dbBuilder.DbContexts, true);

            if (dbBuilder.ShellDbAdded)
            {
                builder.ServiceCollection.AddSmart(ServiceDescriber.Scoped <IRepository <ShellDescriptorRecord>, Repository <ShellDescriptorRecord, ShellDescriptorDbContext> >());
                builder.ServiceCollection.AddSmart(ServiceDescriber.Scoped <IRepository <SettingRecord>, Repository <SettingRecord, ShellDescriptorDbContext> >());
                builder.ServiceCollection.AddSmart(ServiceDescriber.Scoped <IShellDescriptorManager, ShellDescriptorManager>());
            }

            builder.ServiceCollection.AddSmart(EntityFrameworkServices.GetServices(options));


            foreach (var action in dbBuilder.DbConfigurings.Values)
            {
                action(builder.ServiceCollection);
            }

            builder.ServiceCollection.AddSmart(ServiceDescriber.Scoped(
                                                   s =>
            {
                IOptions <DbOptions> dbOps = s.GetRequiredService <IOptions <DbOptions> >();
                return(new DbContextResources(s, dbBuilder.DefaultDbConnectionName, _dbConnectionMappings));
            },
                                                   SmartOptions.Replace));

            builder.ServiceCollection.TryAddScoped <IDatabaseContext>(s => s.GetRequiredService <DbContextResources>());

            return(builder);
        }
Esempio n. 4
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 <IApplicationBuilderFactory, ApplicationBuilderFactory>());

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

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

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

            // TODO: Do we expect this to be provide by the runtime eventually?
            yield return(describer.Singleton <ILoggerFactory, LoggerFactory>());

            yield return(describer.Scoped(typeof(IContextAccessor <>), typeof(ContextAccessor <>)));

            foreach (var service in OptionsServices.GetDefaultServices())
            {
                yield return(service);
            }

            foreach (var service in DataProtectionServices.GetDefaultServices())
            {
                yield return(service);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 为 Asp.Net Identity 配置 Dapper 持久化存储。
        /// </summary>
        /// <typeparam name="TUser">用户类型。</typeparam>
        /// <typeparam name="TRole">角色类型。</typeparam>
        /// <param name="builder"></param>
        /// <returns></returns>
        internal static IdentityBuilder AddDapperStores <TUser, TRole>(this IdentityBuilder builder)
            where TUser : UserBase
            where TRole : RoleBase
        {
            builder.Services.AddSmart(ServiceDescriber.Scoped <IUserStore <TUser>, DapperUserStore <TUser, TRole> >(SmartOptions.Replace));
            builder.Services.AddSmart(ServiceDescriber.Scoped <IRoleStore <TRole>, DapperRoleStore <TRole> >(SmartOptions.Replace));

            return(builder);
        }
Esempio n. 6
0
        public override void ConfigureServices(SchubertServicesBuilder servicesBuilder, SchubertWebOptions options)
        {
            var identitySvcdescriptor = ServiceDescriber.Scoped <IIdentityService, TIdentityService>();

            servicesBuilder.ServiceCollection.AddSmart(identitySvcdescriptor);

            servicesBuilder.ServiceCollection
            .AddIdentity <TUser, TRole>(iop => _configure?.Invoke(iop))
            .AddDefaultTokenProviders()
            .AddDapperStores <TUser, TRole>();
        }
Esempio n. 7
0
        public IEnumerable<IServiceDescriptor> DefineServices()
        {
            var describer = new ServiceDescriber();
            yield return describer.Singleton<ICall, CallOne>();
            yield return describer.Scoped<ICall, CallTwo>();
            yield return describer.Transient<ICall, CallThree>();

            yield return describer.Transient<ITypeActivator, TypeActivator>();
            yield return describer.Describe(
                typeof(IContextAccessor<>),
                typeof(ContextAccessor<>),
                implementationInstance: null,
                lifecycle: LifecycleKind.Scoped);
        }
Esempio n. 8
0
        public IEnumerable <IServiceDescriptor> DefineServices()
        {
            var describer = new ServiceDescriber();

            yield return(describer.Singleton <ICall, CallOne>());

            yield return(describer.Scoped <ICall, CallTwo>());

            yield return(describer.Transient <ICall, CallThree>());

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

            yield return(describer.Describe(
                             typeof(IContextAccessor <>),
                             typeof(ContextAccessor <>),
                             implementationInstance: null,
                             lifecycle: LifecycleKind.Scoped));
        }
        public static IEnumerable <IServiceDescriptor> DefaultServices()
        {
            var describer = new ServiceDescriber();

            yield return(describer.Transient <IFakeService, FakeService>());

            yield return(describer.Transient <IFakeMultipleService, FakeOneMultipleService>());

            yield return(describer.Transient <IFakeMultipleService, FakeTwoMultipleService>());

            yield return(describer.Transient <IFakeOuterService, FakeOuterService>());

            yield return(describer.Instance <IFakeServiceInstance>(new FakeService()
            {
                Message = "Instance"
            }));

            yield return(describer.Scoped <IFakeScopedService, FakeService>());

            yield return(describer.Singleton <IFakeSingletonService, FakeService>());

            yield return(describer.Transient <IFakeFallbackService, FakeService>());

            yield return(describer.Transient <IDependOnNonexistentService, DependOnNonexistentService>());

            yield return(describer.Describe(
                             typeof(IFakeOpenGenericService <string>),
                             typeof(FakeService),
                             implementationInstance: null,
                             lifecycle: LifecycleKind.Transient));

            yield return(describer.Describe(
                             typeof(IFakeOpenGenericService <>),
                             typeof(FakeOpenGenericService <>),
                             implementationInstance: null,
                             lifecycle: LifecycleKind.Transient));
        }
Esempio n. 10
0
        public static IEnumerable<IServiceDescriptor> DefaultServices()
        {
            var describer = new ServiceDescriber();

            yield return describer.Transient<IFakeService, FakeService>();
            yield return describer.Transient<IFakeMultipleService, FakeOneMultipleService>();
            yield return describer.Transient<IFakeMultipleService, FakeTwoMultipleService>();
            yield return describer.Transient<IFakeOuterService, FakeOuterService>();
            yield return describer.Instance<IFakeServiceInstance>(new FakeService() { Message = "Instance" });
            yield return describer.Scoped<IFakeScopedService, FakeService>();
            yield return describer.Singleton<IFakeSingletonService, FakeService>();
            yield return describer.Transient<IFakeFallbackService, FakeService>();
            yield return describer.Transient<IDependOnNonexistentService, DependOnNonexistentService>();
            yield return describer.Describe(
                typeof(IFakeOpenGenericService<string>),
                typeof(FakeService),
                implementationInstance: null,
                lifecycle: LifecycleKind.Transient);
            yield return describer.Describe(
                typeof(IFakeOpenGenericService<>),
                typeof(FakeOpenGenericService<>),
                implementationInstance: null,
                lifecycle: LifecycleKind.Transient);
        }
Esempio n. 11
0
        public static IEnumerable <IServiceDescriptor> GetDefaultServices(IConfiguration configuration = null)
        {
            var describe = new ServiceDescriber(configuration);

            //
            // Options and core services.
            //
            yield return(describe.Transient <IConfigureOptions <MvcOptions>, MvcOptionsSetup>());

            yield return(describe.Transient <IConfigureOptions <RazorViewEngineOptions>, RazorViewEngineOptionsSetup>());

            yield return(describe.Transient <IAssemblyProvider, DefaultAssemblyProvider>());

            yield return(describe.Transient(typeof(INestedProviderManager <>), typeof(NestedProviderManager <>)));

            yield return(describe.Transient(typeof(INestedProviderManagerAsync <>), typeof(NestedProviderManagerAsync <>)));

            yield return(describe.Transient <MvcMarkerService, MvcMarkerService>());

            //
            // Core action discovery, filters and action execution.
            //
            // These are consumed only when creating action descriptors, then they can be de-allocated
            yield return(describe.Transient <IControllerModelBuilder, DefaultControllerModelBuilder>());

            yield return(describe.Transient <IActionModelBuilder, DefaultActionModelBuilder>());

            // This accesses per-request services to activate the controller
            yield return(describe.Transient <IControllerFactory, DefaultControllerFactory>());

            // This has a cache, so it needs to be a singleton
            yield return(describe.Singleton <IControllerActivator, DefaultControllerActivator>());

            // This accesses per-reqest services
            yield return(describe.Transient <IActionInvokerFactory, ActionInvokerFactory>());

            // This provider needs access to the per-request services, but might be used many times for a given
            // request.
            yield return(describe.Scoped <INestedProvider <ActionConstraintProviderContext>,
                                          DefaultActionConstraintProvider>());

            yield return(describe.Singleton <IActionSelectorDecisionTreeProvider, ActionSelectorDecisionTreeProvider>());

            yield return(describe.Scoped <IActionSelector, DefaultActionSelector>());

            yield return(describe.Transient <IControllerActionArgumentBinder, DefaultControllerActionArgumentBinder>());

            yield return(describe.Transient <INestedProvider <ActionDescriptorProviderContext>,
                                             ControllerActionDescriptorProvider>());

            yield return(describe.Transient <INestedProvider <ActionInvokerProviderContext>,
                                             ControllerActionInvokerProvider>());

            yield return(describe.Singleton <IActionDescriptorsCollectionProvider,
                                             DefaultActionDescriptorsCollectionProvider>());

            // The IGlobalFilterProvider is used to build the action descriptors (likely once) and so should
            // remain transient to avoid keeping it in memory.
            yield return(describe.Transient <IGlobalFilterProvider, DefaultGlobalFilterProvider>());

            yield return(describe.Transient <INestedProvider <FilterProviderContext>, DefaultFilterProvider>());

            //
            // Dataflow - ModelBinding, Validation and Formatting
            //
            yield return(describe.Transient <IModelMetadataProvider, DataAnnotationsModelMetadataProvider>());

            yield return(describe.Scoped <IActionBindingContextProvider, DefaultActionBindingContextProvider>());

            yield return(describe.Transient <IInputFormatterSelector, DefaultInputFormatterSelector>());

            yield return(describe.Scoped <IInputFormattersProvider, DefaultInputFormattersProvider>());

            yield return(describe.Transient <IModelBinderProvider, DefaultModelBindersProvider>());

            yield return(describe.Scoped <ICompositeModelBinder, CompositeModelBinder>());

            yield return(describe.Transient <IValueProviderFactoryProvider, DefaultValueProviderFactoryProvider>());

            yield return(describe.Scoped <ICompositeValueProviderFactory, CompositeValueProviderFactory>());

            yield return(describe.Transient <IOutputFormattersProvider, DefaultOutputFormattersProvider>());

            yield return(describe.Instance <JsonOutputFormatter>(new JsonOutputFormatter()));

            yield return(describe.Transient <IModelValidatorProviderProvider, DefaultModelValidatorProviderProvider>());

            yield return(describe.Scoped <ICompositeModelValidatorProvider, CompositeModelValidatorProvider>());

            yield return(describe.Transient <IBodyModelValidator, DefaultBodyModelValidator>());

            yield return(describe.Transient <IValidationExcludeFiltersProvider, DefaultValidationExcludeFiltersProvider>());

            //
            // Razor, Views and runtime compilation
            //

            // The provider is inexpensive to initialize and provides ViewEngines that may require request
            // specific services.
            yield return(describe.Scoped <ICompositeViewEngine, CompositeViewEngine>());

            yield return(describe.Transient <IViewEngineProvider, DefaultViewEngineProvider>());

            // Transient since the IViewLocationExpanders returned by the instance is cached by view engines.
            yield return(describe.Transient <IViewLocationExpanderProvider, DefaultViewLocationExpanderProvider>());

            // Caches view locations that are valid for the lifetime of the application.
            yield return(describe.Singleton <IViewLocationCache, DefaultViewLocationCache>());

            yield return(describe.Singleton <IRazorFileSystemCache, DefaultRazorFileSystemCache>());

            // The host is designed to be discarded after consumption and is very inexpensive to initialize.
            yield return(describe.Transient <IMvcRazorHost>(serviceProvider =>
            {
                var cachedFileSystem = serviceProvider.GetRequiredService <IRazorFileSystemCache>();
                return new MvcRazorHost(cachedFileSystem);
            }));

            // Caches compilation artifacts across the lifetime of the application.
            yield return(describe.Singleton <ICompilerCache, CompilerCache>());

            // This caches compilation related details that are valid across the lifetime of the application
            // and is required to be a singleton.
            yield return(describe.Singleton <ICompilationService, RoslynCompilationService>());

            // Both the compiler cache and roslyn compilation service hold on the compilation related
            // caches. RazorCompilation service is just an adapter service, and it is transient to ensure
            // the IMvcRazorHost dependency does not maintain state.
            yield return(describe.Transient <IRazorCompilationService, RazorCompilationService>());

            // The ViewStartProvider needs to be able to consume scoped instances of IRazorPageFactory
            yield return(describe.Scoped <IViewStartProvider, ViewStartProvider>());

            yield return(describe.Transient <IRazorViewFactory, RazorViewFactory>());

            yield return(describe.Singleton <IRazorPageActivator, RazorPageActivator>());

            // Virtual path view factory needs to stay scoped so views can get get scoped services.
            yield return(describe.Scoped <IRazorPageFactory, VirtualPathRazorPageFactory>());

            //
            // View and rendering helpers
            //

            yield return(describe.Transient <IHtmlHelper, HtmlHelper>());

            yield return(describe.Transient(typeof(IHtmlHelper <>), typeof(HtmlHelper <>)));

            yield return(describe.Scoped <IUrlHelper, UrlHelper>());

            // Only want one ITagHelperActivator so it can cache Type activation information. Types won't conflict.
            yield return(describe.Singleton <ITagHelperActivator, DefaultTagHelperActivator>());

            // DefaultHtmlGenerator is pretty much stateless but depends on Scoped services such as IUrlHelper and
            // IActionBindingContextProvider. Therefore it too is scoped.
            yield return(describe.Transient <IHtmlGenerator, DefaultHtmlGenerator>());

            yield return(describe.Transient <IViewComponentSelector, DefaultViewComponentSelector>());

            yield return(describe.Singleton <IViewComponentActivator, DefaultViewComponentActivator>());

            yield return(describe.Transient <IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>());

            yield return(describe.Transient <INestedProvider <ViewComponentInvokerProviderContext>,
                                             DefaultViewComponentInvokerProvider>());

            yield return(describe.Transient <IViewComponentHelper, DefaultViewComponentHelper>());

            //
            // Security and Authorization
            //

            yield return(describe.Transient <IAuthorizationService, DefaultAuthorizationService>());

            yield return(describe.Singleton <IClaimUidExtractor, DefaultClaimUidExtractor>());

            yield return(describe.Singleton <AntiForgery, AntiForgery>());

            yield return(describe.Singleton <IAntiForgeryAdditionalDataProvider,
                                             DefaultAntiForgeryAdditionalDataProvider>());

            //
            // Api Description
            //

            yield return(describe.Singleton <IApiDescriptionGroupCollectionProvider,
                                             ApiDescriptionGroupCollectionProvider>());

            yield return(describe.Transient <INestedProvider <ApiDescriptionProviderContext>,
                                             DefaultApiDescriptionProvider>());
        }
Esempio n. 12
0
        public static IEnumerable <IServiceDescriptor> GetDefaultServices(IConfiguration configuration)
        {
            var describe = new ServiceDescriber(configuration);

            yield return(describe.Transient <IOptionsSetup <MvcOptions>, MvcOptionsSetup>());

            yield return(describe.Transient <IControllerFactory, DefaultControllerFactory>());

            yield return(describe.Singleton <IControllerActivator, DefaultControllerActivator>());

            yield return(describe.Scoped <IActionSelector, DefaultActionSelector>());

            yield return(describe.Transient <IActionInvokerFactory, ActionInvokerFactory>());

            yield return(describe.Transient <IControllerAssemblyProvider, DefaultControllerAssemblyProvider>());

            yield return(describe.Transient <IActionDiscoveryConventions, DefaultActionDiscoveryConventions>());

            yield return(describe.Instance <IMvcRazorHost>(new MvcRazorHost(typeof(RazorPage).FullName)));

            yield return(describe.Transient <ICompilationService, RoslynCompilationService>());

            yield return(describe.Singleton <IViewEngineProvider, DefaultViewEngineProvider>());

            yield return(describe.Scoped <ICompositeViewEngine, CompositeViewEngine>());

            yield return(describe.Singleton <IRazorCompilationService, RazorCompilationService>());

            yield return(describe.Singleton <IViewStartProvider, ViewStartProvider>());

            yield return(describe.Singleton <IRazorPageActivator, RazorPageActivator>());

            // Virtual path view factory needs to stay scoped so views can get get scoped services.
            yield return(describe.Scoped <IRazorPageFactory, VirtualPathRazorPageFactory>());

            yield return(describe.Singleton <IFileInfoCache, ExpiringFileInfoCache>());

            yield return(describe.Transient <INestedProvider <ActionDescriptorProviderContext>,
                                             ReflectedActionDescriptorProvider>());

            yield return(describe.Transient <INestedProvider <ActionInvokerProviderContext>,
                                             ReflectedActionInvokerProvider>());

            yield return(describe.Singleton <IActionDescriptorsCollectionProvider,
                                             DefaultActionDescriptorsCollectionProvider>());

            yield return(describe.Transient <IModelMetadataProvider, DataAnnotationsModelMetadataProvider>());

            yield return(describe.Scoped <IActionBindingContextProvider, DefaultActionBindingContextProvider>());

            yield return(describe.Transient <IInputFormatter, JsonInputFormatter>());

            yield return(describe.Transient <IInputFormatter, XmlSerializerInputFormatter>());

            yield return(describe.Transient <IInputFormatter, XmlDataContractSerializerInputFormatter>());

            yield return(describe.Transient <IInputFormatterProvider, TempInputFormatterProvider>());

            yield return(describe.Transient <IModelBinderProvider, DefaultModelBindersProvider>());

            yield return(describe.Scoped <ICompositeModelBinder, CompositeModelBinder>());

            yield return(describe.Transient <IValueProviderFactoryProvider, DefaultValueProviderFactoryProvider>());

            yield return(describe.Scoped <ICompositeValueProviderFactory, CompositeValueProviderFactory>());

            yield return(describe.Transient <IOutputFormattersProvider, DefaultOutputFormattersProvider>());

            yield return(describe.Transient <INestedProvider <FilterProviderContext>, DefaultFilterProvider>());

            yield return(describe.Transient <IModelValidatorProvider, DataAnnotationsModelValidatorProvider>());

            yield return(describe.Transient <IModelValidatorProvider, DataMemberModelValidatorProvider>());

            yield return(describe.Scoped <IUrlHelper, UrlHelper>());

            yield return(describe.Transient <IViewComponentSelector, DefaultViewComponentSelector>());

            yield return(describe.Transient <IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>());

            yield return(describe.Transient <INestedProvider <ViewComponentInvokerProviderContext>,
                                             DefaultViewComponentInvokerProvider>());

            yield return(describe.Transient <IViewComponentHelper, DefaultViewComponentHelper>());

            yield return(describe.Transient <IAuthorizationService, DefaultAuthorizationService>());

            yield return(describe.Singleton <IClaimUidExtractor, DefaultClaimUidExtractor>());

            yield return(describe.Singleton <AntiForgery, AntiForgery>());

            yield return(describe.Singleton <IAntiForgeryAdditionalDataProvider,
                                             DefaultAntiForgeryAdditionalDataProvider>());

            yield return
                (describe.Describe(
                     typeof(INestedProviderManager <>),
                     typeof(NestedProviderManager <>),
                     implementationInstance: null,
                     lifecycle: LifecycleKind.Transient));

            yield return
                (describe.Describe(
                     typeof(INestedProviderManagerAsync <>),
                     typeof(NestedProviderManagerAsync <>),
                     implementationInstance: null,
                     lifecycle: LifecycleKind.Transient));

            yield return(describe.Transient <IHtmlHelper, HtmlHelper>());

            yield return
                (describe.Describe(
                     typeof(IHtmlHelper <>),
                     typeof(HtmlHelper <>),
                     implementationInstance: null,
                     lifecycle: LifecycleKind.Transient));
        }
Esempio n. 13
0
        public static IEnumerable<IServiceDescriptor> GetDefaultServices(IConfiguration configuration)
        {
            var describe = new ServiceDescriber(configuration);

            yield return describe.Transient<IOptionsSetup<MvcOptions>, MvcOptionsSetup>();

            yield return describe.Transient<IControllerFactory, DefaultControllerFactory>();
            yield return describe.Singleton<IControllerActivator, DefaultControllerActivator>();
            yield return describe.Scoped<IActionSelector, DefaultActionSelector>();
            yield return describe.Transient<IActionInvokerFactory, ActionInvokerFactory>();
            yield return describe.Transient<IControllerAssemblyProvider, DefaultControllerAssemblyProvider>();
            yield return describe.Transient<IActionDiscoveryConventions, DefaultActionDiscoveryConventions>();

            yield return describe.Instance<IMvcRazorHost>(new MvcRazorHost(typeof(RazorPage).FullName));

            yield return describe.Transient<ICompilationService, RoslynCompilationService>();

            yield return describe.Singleton<IViewEngineProvider, DefaultViewEngineProvider>();
            yield return describe.Scoped<ICompositeViewEngine, CompositeViewEngine>();
            yield return describe.Singleton<IRazorCompilationService, RazorCompilationService>();
            yield return describe.Singleton<IViewStartProvider, ViewStartProvider>();

            yield return describe.Singleton<IRazorPageActivator, RazorPageActivator>();
            // Virtual path view factory needs to stay scoped so views can get get scoped services.
            yield return describe.Scoped<IRazorPageFactory, VirtualPathRazorPageFactory>();
            yield return describe.Singleton<IFileInfoCache, ExpiringFileInfoCache>();

            yield return describe.Transient<INestedProvider<ActionDescriptorProviderContext>,
                                            ReflectedActionDescriptorProvider>();
            yield return describe.Transient<INestedProvider<ActionInvokerProviderContext>,
                                            ReflectedActionInvokerProvider>();
            yield return describe.Singleton<IActionDescriptorsCollectionProvider,
                DefaultActionDescriptorsCollectionProvider>();

            yield return describe.Transient<IModelMetadataProvider, DataAnnotationsModelMetadataProvider>();
            yield return describe.Scoped<IActionBindingContextProvider, DefaultActionBindingContextProvider>();

            yield return describe.Transient<IInputFormatter, JsonInputFormatter>();
            yield return describe.Transient<IInputFormatter, XmlSerializerInputFormatter>();
            yield return describe.Transient<IInputFormatter, XmlDataContractSerializerInputFormatter>();
            yield return describe.Transient<IInputFormatterProvider, TempInputFormatterProvider>();

            yield return describe.Transient<IModelBinderProvider, DefaultModelBindersProvider>();
            yield return describe.Scoped<ICompositeModelBinder, CompositeModelBinder>();
            yield return describe.Transient<IValueProviderFactoryProvider, DefaultValueProviderFactoryProvider>();
            yield return describe.Scoped<ICompositeValueProviderFactory, CompositeValueProviderFactory>();
            yield return describe.Transient<IOutputFormattersProvider, DefaultOutputFormattersProvider>();

            yield return describe.Transient<INestedProvider<FilterProviderContext>, DefaultFilterProvider>();

            yield return describe.Transient<IModelValidatorProvider, DataAnnotationsModelValidatorProvider>();
            yield return describe.Transient<IModelValidatorProvider, DataMemberModelValidatorProvider>();

            yield return describe.Scoped<IUrlHelper, UrlHelper>();

            yield return describe.Transient<IViewComponentSelector, DefaultViewComponentSelector>();
            yield return describe.Transient<IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>();
            yield return describe.Transient<INestedProvider<ViewComponentInvokerProviderContext>,
                DefaultViewComponentInvokerProvider>();
            yield return describe.Transient<IViewComponentHelper, DefaultViewComponentHelper>();

            yield return describe.Transient<IAuthorizationService, DefaultAuthorizationService>();
            yield return describe.Singleton<IClaimUidExtractor, DefaultClaimUidExtractor>();
            yield return describe.Singleton<AntiForgery, AntiForgery>();
            yield return describe.Singleton<IAntiForgeryAdditionalDataProvider,
                DefaultAntiForgeryAdditionalDataProvider>();

            yield return
               describe.Describe(
                   typeof(INestedProviderManager<>),
                   typeof(NestedProviderManager<>),
                   implementationInstance: null,
                   lifecycle: LifecycleKind.Transient);

            yield return
                describe.Describe(
                    typeof(INestedProviderManagerAsync<>),
                    typeof(NestedProviderManagerAsync<>),
                    implementationInstance: null,
                    lifecycle: LifecycleKind.Transient);

            yield return describe.Transient<IHtmlHelper, HtmlHelper>();
            yield return
                describe.Describe(
                    typeof(IHtmlHelper<>),
                    typeof(HtmlHelper<>),
                    implementationInstance: null,
                    lifecycle: LifecycleKind.Transient);
        }
Esempio n. 14
0
        public static IEnumerable <IServiceDescriptor> GetDefaultServices(IConfiguration configuration)
        {
            var describe = new ServiceDescriber(configuration);

            yield return(describe.Transient <IOptionsSetup <MvcOptions>, MvcOptionsSetup>());

            yield return(describe.Transient <IControllerFactory, DefaultControllerFactory>());

            yield return(describe.Singleton <IControllerActivator, DefaultControllerActivator>());

            yield return(describe.Singleton <IActionSelectorDecisionTreeProvider, ActionSelectorDecisionTreeProvider>());

            yield return(describe.Scoped <IActionSelector, DefaultActionSelector>());

            yield return(describe.Transient <IActionInvokerFactory, ActionInvokerFactory>());

            yield return(describe.Transient <IControllerAssemblyProvider, DefaultControllerAssemblyProvider>());

            yield return(describe.Transient <IActionDiscoveryConventions, DefaultActionDiscoveryConventions>());

            // The host is designed to be discarded after consumption and is very inexpensive to initialize.
            yield return(describe.Transient <IMvcRazorHost, MvcRazorHost>());

            yield return(describe.Singleton <ICompilationService, RoslynCompilationService>());

            yield return(describe.Singleton <IRazorCompilationService, RazorCompilationService>());

            yield return(describe.Singleton <IViewEngineProvider, DefaultViewEngineProvider>());

            yield return(describe.Scoped <ICompositeViewEngine, CompositeViewEngine>());

            yield return(describe.Singleton <IViewStartProvider, ViewStartProvider>());

            yield return(describe.Transient <IRazorView, RazorView>());

            yield return(describe.Singleton <IRazorPageActivator, RazorPageActivator>());

            // Virtual path view factory needs to stay scoped so views can get get scoped services.
            yield return(describe.Scoped <IRazorPageFactory, VirtualPathRazorPageFactory>());

            yield return(describe.Singleton <IFileInfoCache, ExpiringFileInfoCache>());

            yield return(describe.Transient <INestedProvider <ActionDescriptorProviderContext>,
                                             ReflectedActionDescriptorProvider>());

            yield return(describe.Transient <INestedProvider <ActionInvokerProviderContext>,
                                             ReflectedActionInvokerProvider>());

            yield return(describe.Singleton <IActionDescriptorsCollectionProvider,
                                             DefaultActionDescriptorsCollectionProvider>());

            yield return(describe.Transient <IModelMetadataProvider, DataAnnotationsModelMetadataProvider>());

            yield return(describe.Scoped <IActionBindingContextProvider, DefaultActionBindingContextProvider>());

            yield return(describe.Transient <IInputFormatterSelector, DefaultInputFormatterSelector>());

            yield return(describe.Scoped <IInputFormattersProvider, DefaultInputFormattersProvider>());

            yield return(describe.Transient <IModelBinderProvider, DefaultModelBindersProvider>());

            yield return(describe.Scoped <ICompositeModelBinder, CompositeModelBinder>());

            yield return(describe.Transient <IValueProviderFactoryProvider, DefaultValueProviderFactoryProvider>());

            yield return(describe.Scoped <ICompositeValueProviderFactory, CompositeValueProviderFactory>());

            yield return(describe.Transient <IOutputFormattersProvider, DefaultOutputFormattersProvider>());

            yield return(describe.Instance <JsonOutputFormatter>(
                             new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), indent: false)));

            // The IGlobalFilterProvider is used to build the action descriptors (likely once) and so should
            // remain transient to avoid keeping it in memory.
            yield return(describe.Transient <IGlobalFilterProvider, DefaultGlobalFilterProvider>());

            yield return(describe.Transient <INestedProvider <FilterProviderContext>, DefaultFilterProvider>());

            yield return(describe.Transient <IModelValidatorProviderProvider, DefaultModelValidatorProviderProvider>());

            yield return(describe.Scoped <ICompositeModelValidatorProvider, CompositeModelValidatorProvider>());

            yield return(describe.Scoped <IUrlHelper, UrlHelper>());

            yield return(describe.Transient <IViewComponentSelector, DefaultViewComponentSelector>());

            yield return(describe.Singleton <IViewComponentActivator, DefaultViewComponentActivator>());

            yield return(describe.Transient <IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>());

            yield return(describe.Transient <INestedProvider <ViewComponentInvokerProviderContext>,
                                             DefaultViewComponentInvokerProvider>());

            yield return(describe.Transient <IViewComponentHelper, DefaultViewComponentHelper>());

            yield return(describe.Transient <IAuthorizationService, DefaultAuthorizationService>());

            yield return(describe.Singleton <IClaimUidExtractor, DefaultClaimUidExtractor>());

            yield return(describe.Singleton <AntiForgery, AntiForgery>());

            yield return(describe.Singleton <IAntiForgeryAdditionalDataProvider,
                                             DefaultAntiForgeryAdditionalDataProvider>());

            yield return
                (describe.Describe(
                     typeof(INestedProviderManager <>),
                     typeof(NestedProviderManager <>),
                     implementationInstance: null,
                     lifecycle: LifecycleKind.Transient));

            yield return
                (describe.Describe(
                     typeof(INestedProviderManagerAsync <>),
                     typeof(NestedProviderManagerAsync <>),
                     implementationInstance: null,
                     lifecycle: LifecycleKind.Transient));

            yield return(describe.Transient <IHtmlHelper, HtmlHelper>());

            yield return
                (describe.Describe(
                     typeof(IHtmlHelper <>),
                     typeof(HtmlHelper <>),
                     implementationInstance: null,
                     lifecycle: LifecycleKind.Transient));

            yield return(describe.Transient <MvcMarkerService, MvcMarkerService>());
        }
Esempio n. 15
0
        public static IEnumerable <SmartServiceDescriptor> GetServices()
        {
            yield return(ServiceDescriber.Scoped <SwiftyWorkContext, SwiftyWorkContext>());

            yield return(ServiceDescriber.Singleton <IWorkContextProvider, SwiftyWorkContextProvider>(SmartOptions.Append));
        }