// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddBehlogServices(Configuration); services.AddMvc(_ => { _.UseYeKeModelBinder(); }); services.AddDistributedMemoryCache(); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(30); options.Cookie.IsEssential = true; }); services.AddDNTCommonWeb(); IMvcBuilder mvc = services.AddControllersWithViews(); mvc = services.AddRazorPages(); mvc.AddApplicationPart(typeof( Admin.Controllers.PostController) .Assembly); mvc.AddApplicationPart(typeof( Identity.Controllers.LoginController) .Assembly); services.Configure <RouteOptions>(_ => { _.ConstraintMap.Add("reserved", typeof(BehlogReservedRouteConstraint)); }); #if DEBUG if (Env.IsDevelopment()) { mvc.AddRazorRuntimeCompilation(); } #endif }
/// <summary> /// Finds all the types that are <see cref="Controller" /> or <see cref="FeatureController" />and add them to the Api /// as services. /// </summary> /// <param name="builder">The builder</param> /// <param name="services">The services to look into</param> /// <returns>The Mvc builder</returns> public static IMvcBuilder AddControllers(this IMvcBuilder builder, IServiceCollection services) { // Adds Controllers with API endpoints IEnumerable <ServiceDescriptor> controllerTypes = services.Where(s => s.ServiceType.GetTypeInfo().BaseType == typeof(Controller)); foreach (ServiceDescriptor controllerType in controllerTypes) { builder.AddApplicationPart(controllerType.ServiceType.GetTypeInfo().Assembly); } // Adds FeatureControllers with API endpoints. IEnumerable <ServiceDescriptor> featureControllerTypes = services.Where(s => s.ServiceType.GetTypeInfo().BaseType == typeof(FeatureController)); foreach (ServiceDescriptor featureControllerType in featureControllerTypes) { builder.AddApplicationPart(featureControllerType.ServiceType.GetTypeInfo().Assembly); } // Adds ServerNodeContoller with API endpoints. builder.AddApplicationPart(typeof(ServerNodeContoller).Assembly); // Adds PublicController with API endpoints. builder.AddApplicationPart(typeof(PublicController).Assembly); builder.AddControllersAsServices(); return(builder); }
private static IMvcBuilder AddEdityControllers(this IMvcBuilder builder, IEnumerable <Assembly> additionalAssemblies) { builder.AddApplicationPart(typeof(EdityMvcExtensions).GetTypeInfo().Assembly); if (additionalAssemblies != null) { foreach (var assembly in additionalAssemblies) { builder.AddApplicationPart(assembly); } } return(builder); }
public static IMvcBuilder RegisterApplicationParts(this IMvcBuilder mvcBuilder, AssemblyRegistrationList list, params Assembly[] other) { foreach (var o in other) { mvcBuilder.AddApplicationPart(o); } foreach (var a in list.List) { mvcBuilder.AddApplicationPart(a); } return(mvcBuilder); }
/// <summary> /// Finds all the types that are <see cref="Controller"/> and add them to the Api as services. /// </summary> /// <param name="builder">The builder</param> /// <param name="services">The services to look into</param> /// <returns>The Mvc builder</returns> public static IMvcBuilder AddControllers(this IMvcBuilder builder, IServiceCollection services) { var controllerTypes = services.Where(s => s.ServiceType.GetTypeInfo().BaseType == typeof(Controller)); foreach (var controllerType in controllerTypes) { builder.AddApplicationPart(controllerType.ServiceType.GetTypeInfo().Assembly); } builder.AddApplicationPart(typeof(Controllers.NodeController).Assembly); builder.AddControllersAsServices(); return(builder); }
public static IServiceCollection AddDeploymentMvc(this IServiceCollection services, EnvironmentConfiguration environmentConfiguration, IKeyValueConfiguration configuration, ILogger logger, IApplicationAssemblyResolver applicationAssemblyResolver) { ViewAssemblyLoader.LoadViewAssemblies(logger); var filteredAssemblies = applicationAssemblyResolver.GetAssemblies(); IMvcBuilder mvcBuilder = services.AddMvc( options => { options.InputFormatters.Insert(0, new XWwwFormUrlEncodedFormatter()); options.Filters.Add <ModelValidatorFilterAttribute>(); }) .AddNewtonsoftJson( options => { options.SerializerSettings.Converters.Add(new DateConverter()); options.SerializerSettings.Formatting = Formatting.Indented; }); foreach (Assembly filteredAssembly in filteredAssemblies) { logger.Debug("Adding assembly {Assembly} to MVC application parts", filteredAssembly.FullName); mvcBuilder.AddApplicationPart(filteredAssembly); } var viewAssemblies = AssemblyLoadContext.Default.Assemblies .Where(assembly => !assembly.IsDynamic && (assembly.GetName().Name?.Contains("View") ?? false)) .ToArray(); foreach (var item in viewAssemblies) { mvcBuilder.AddApplicationPart(item); } if (environmentConfiguration.ToHostEnvironment().IsDevelopment() || configuration.ValueOrDefault(StartupConstants.RuntimeCompilationEnabled)) { mvcBuilder.AddRazorRuntimeCompilation(); } mvcBuilder .AddControllersAsServices(); services.AddAntiforgery(); return(services); }
public static IServiceCollection AddUserManagement(this IServiceCollection services, IMvcBuilder mvcBuilder, IHostingEnvironment hosting) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (mvcBuilder == null) { throw new ArgumentNullException(nameof(mvcBuilder)); } if (hosting == null) { throw new ArgumentNullException(nameof(hosting)); } var assembly = typeof(UserController).Assembly; var embeddedFileProvider = new EmbeddedFileProvider(assembly); var compositeProvider = new CompositeFileProvider(hosting.ContentRootFileProvider, embeddedFileProvider); services.Configure <RazorViewEngineOptions>(options => { options.FileProviders.Add(compositeProvider); }); mvcBuilder.AddApplicationPart(assembly); return(services); }
/// <summary> /// Adds a dynamic controller. /// </summary> /// <param name="mvcBuilder">An <see cref="IMvcBuilder"/> instance.</param> /// <param name="controllerContractType">The controller type.</param> /// <param name="serviceType">The service type.</param> /// <returns>The <see cref="IMvcBuilder"/> instance.</returns> private static IMvcBuilder AddDynamicController( this IMvcBuilder mvcBuilder, Type controllerContractType, Type serviceType) { string controllerName = ControllerFactory.GetTypeName(controllerContractType); Type controllerType = controllerTypes.FirstOrDefault(ct => ct.FullName == controllerName); if (controllerType == null) { controllerType = factory.CreateControllerType(controllerContractType, serviceType); controllerTypes.Add(controllerType); } mvcBuilder.AddApplicationPart(controllerType.Assembly); mvcBuilder.Services.AddTransient( controllerType, (sp) => { var service = sp.GetService(serviceType); var controller = factory.CreateController(controllerType, service); return(controller); }); return(mvcBuilder); }
public static IMvcBuilder AddAutoApi <T>(this IMvcBuilder mvcBuilder, string route = null) where T : LiteDbModel { AssemblyName assemblyName = typeof(BaseController <>).Assembly.GetName(); AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndCollect); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name); Type newControllerParentType = typeof(BaseController <>).MakeGenericType(typeof(T)); string newControllerName = $"{typeof(T).Name}Controller"; TypeBuilder typeBuilder = moduleBuilder.DefineType(newControllerName, TypeAttributes.Public, newControllerParentType); if (!string.IsNullOrEmpty(route)) { ConstructorInfo constructorInfo = typeof(RouteAttribute).GetConstructor(new[] { typeof(string) }); CustomAttributeBuilder routeAttributeBuilder = new CustomAttributeBuilder(constructorInfo, new object[] { route }); typeBuilder.SetCustomAttribute(routeAttributeBuilder); } Type newType = typeBuilder.CreateType(); mvcBuilder.AddApplicationPart(newType.Assembly).AddControllersAsServices(); return(mvcBuilder); }
public static IMvcBuilder AddApplicationPart(this IMvcBuilder builder, Func <Assembly, bool> canScan = null) { if (null == canScan) { canScan = (file) => true; } foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { try { if (!canScan(assembly)) { continue; } builder.AddApplicationPart(assembly); } catch (BadImageFormatException) { } catch (FileLoadException) { } catch (Exception) { } } return(builder); }
private void LoadPrivateBinAssemblies(IMvcBuilder mvcBuilder) { var binPath = Path.Combine(WebRoot, "privatebin"); if (Directory.Exists(binPath)) { var files = Directory.GetFiles(binPath); foreach (var file in files) { if (!file.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase) && !file.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase)) { continue; } try { var asm = AssemblyLoadContext.Default.LoadFromAssemblyPath(file); mvcBuilder.AddApplicationPart(asm); LoadedPrivateAssemblies.Add(file); } catch (Exception ex) { FailedPrivateAssemblies.Add(file + "\n - " + ex.Message); } } } }
public static IMvcBuilder AddGrpcHttp(this IMvcBuilder mvcCoreBuilder, Action <GrpcHttpOptions> configure) { IServiceCollection compileServices = new ServiceCollection(); compileServices.AddSingleton <IServiceCompiler, DefaultServiceCompiler>(); compileServices.AddSingleton <IControllerDescriptorGenerator, DefaultControllerDescriptorGenerator>(); GrpcHttpOptions options = new GrpcHttpOptions { CompileServices = compileServices }; configure(options); IServiceProvider sp = compileServices.BuildServiceProvider(); IControllerDescriptorGenerator csg = sp.GetRequiredService <IControllerDescriptorGenerator>(); IServiceCompiler sc = sp.GetRequiredService <IServiceCompiler>(); foreach (Type grpcServiceType in options.GrpcServices) { ControllerDescriptor controllerDescriptor = csg.Generate(grpcServiceType); foreach (IFilter filter in options.Filters) { filter.Filter(controllerDescriptor); } mvcCoreBuilder = mvcCoreBuilder.AddApplicationPart(sc.Compile(controllerDescriptor)); } mvcCoreBuilder.Services.AddSingleton <IServerCallContextFactory, DefaultServerCallContextFactory>(); return(mvcCoreBuilder); }
public static IServiceCollection AddSigninUp(this IServiceCollection services, IMvcBuilder mvcBuilder, IConfiguration configuration) { // Controllers mvcBuilder.AddApplicationPart(typeof(OrganizationsController).GetTypeInfo().Assembly); //------------------------- Commands // InitOrganizationSigningUp services.AddScoped <IInitOrganizationSigningUpService, InitOrganizationSigningUpService>(); services.AddScoped <IInitOrganizationSigningUpRepository, InitOrganizationSigningUpRepository>(); // CompleteOrganizationSigningUp services.Configure <CompleteOrganizationSigningUpPageInfo>( configuration.GetSection("CompleteOrganizationSigningUpPageInfo")); services.AddScoped <ICompleteOrganizationSigningUpService, CompleteOrganizationSigningUpService>(); services.AddScoped <ICompleteOrganizationSigningUpRepository, CompleteOrganizationSigningUpRepository>(); // CompleteUserSigningUp services.AddScoped <ICompleteUserSigningUpService, CompleteUserSigningUpService>(); //------------------------- Queries // CheckOrganizationSigningUpToken services.AddScoped <ICheckOrganizationSigningUpTokenService, CheckOrganizationSigningUpTokenService>(); services.AddScoped <ICheckOrganizationSigningUpTokenRepository, CheckOrganizationSigningUpTokenRepository>(); // CheckUserSigningUpToken services.AddScoped <ICheckUserSigningUpTokenService, CheckUserSigningUpTokenService>(); services.AddScoped <ICheckUserSigningUpTokenRepository, CheckUserSigningUpTokenRepository>(); return(services); }
private void AddMvcServices(IServiceCollection services) { IMvcBuilder mvcBuilder = services.AddMvc(); List <MetadataReference> metadataReferences = new List <MetadataReference>(); foreach (Assembly assembly in ExtensionManager.Assemblies) { mvcBuilder.AddApplicationPart(assembly); metadataReferences.Add(MetadataReference.CreateFromFile(assembly.Location)); } mvcBuilder.AddRazorOptions( o => { foreach (Assembly assembly in ExtensionManager.Assemblies) { o.FileProviders.Add(new EmbeddedFileProvider(assembly, assembly.GetName().Name)); } Action <RoslynCompilationContext> previous = o.CompilationCallback; o.CompilationCallback = c => { if (previous != null) { previous(c); } c.Compilation = c.Compilation.AddReferences(metadataReferences); }; } ); }
public static void RegisterAssembliesForControllers(this IMvcBuilder mvc, IEnumerable <Assembly> assemblies) { if (assemblies?.Any() == true) { assemblies.ToList().ForEach(assembly => mvc.AddApplicationPart(assembly)); } }
public static IMvcBuilder AddIdentityUtilsAuthenticationControllerAssemblyPart(this IMvcBuilder builder) { builder.RemoveIdentityUtilsAuthenticationControllerAssemblyPart(); builder.AddApplicationPart(controllersAssembly); return(builder); }
public static IMvcBuilder AddUIComposition(this IMvcBuilder builder, string assemblySearchPattern = "*ViewComponents*.dll") { var fileNames = Directory.GetFiles(AppContext.BaseDirectory, assemblySearchPattern); var assemblies = new List <(string BaseNamespace, Assembly Assembly)>(); foreach (var fileName in fileNames) { var assembly = Assembly.LoadFrom(fileName); var attribute = assembly.GetCustomAttribute <UICompositionSupportAttribute>(); if (attribute != null) { assemblies.Add((attribute.BaseNamespace, assembly)); } } assemblies.ForEach(a => { builder.Services.Configure <MvcRazorRuntimeCompilationOptions>(options => { options.FileProviders.Add(new EmbeddedFileProvider(a.Assembly, a.BaseNamespace)); }); builder.AddApplicationPart(a.Assembly); }); return(builder); }
public static IServiceCollection AddUserManagement(this IServiceCollection services, IMvcBuilder mvcBuilder, UserManagementOptions userManagementOptions) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (mvcBuilder == null) { throw new ArgumentNullException(nameof(mvcBuilder)); } if (userManagementOptions == null) { throw new ArgumentNullException(nameof(userManagementOptions)); } var assembly = typeof(HomeController).Assembly; var embeddedFileProvider = new EmbeddedFileProvider(assembly); services.Configure <RazorViewEngineOptions>(options => { options.FileProviders.Add(embeddedFileProvider); }); services.AddSingleton(userManagementOptions); services.AddSingleton <IUiModule>(new UiManagerModuleUI()); mvcBuilder.AddApplicationPart(assembly); return(services); }
public static void ConfigureServices(IMvcBuilder mvcBuilder) { mvcBuilder.AddApplicationPart(typeof(ApiConfiguration).Assembly); var services = mvcBuilder.Services; services.AddAuthorization(Policies.Configure); // Repositories services.AddSingleton <IProductsRepository, InMemoryProductsRepository>(); // Services services.AddScoped <IScopedService, ScopedService>(); // Replace the default authorization policy provider with our own // custom provider which can return authorization policies for given // policy names (instead of using the default policy provider) services.AddSingleton <IAuthorizationPolicyProvider, PermissionsPolicyProvider>(); // Authorization handlers services.AddSingleton <IAuthorizationHandler, Handler01>(); services.AddSingleton <IAuthorizationHandler, Handler02>(); services.AddSingleton <IAuthorizationHandler, Handler03>(); services.AddSingleton <IAuthorizationHandler, MinimumAgeAuthorizationHandler>(); services.AddSingleton <IAuthorizationHandler, HasBadgeHandler>(); services.AddSingleton <IAuthorizationHandler, HasTemporaryPassHandler>(); services.AddSingleton <IAuthorizationHandler, OwnedProductHandler>(); services.AddSingleton <IAuthorizationHandler, PermissionsAuthorizationHandler>(); }
public static IServiceCollection AddModules(this IServiceCollection services, IMvcBuilder mvcBuilder, Action <LocalStorageModuleCatalogOptions> setupAction = null) { services.AddSingleton(services); services.AddSingleton <IModuleInitializer, ModuleInitializer>(); services.AddSingleton <IAssemblyResolver, LoadContextAssemblyResolver>(); services.AddSingleton <IModuleManager, ModuleManager>(); services.AddSingleton <ILocalModuleCatalog, LocalStorageModuleCatalog>(); services.AddSingleton <IModuleCatalog>(provider => provider.GetService <ILocalModuleCatalog>()); services.AddSingleton <IAssemblyResolver, LoadContextAssemblyResolver>(); if (setupAction != null) { services.Configure(setupAction); } var providerSnapshot = services.BuildServiceProvider(); var manager = providerSnapshot.GetRequiredService <IModuleManager>(); var moduleCatalog = providerSnapshot.GetRequiredService <ILocalModuleCatalog>(); manager.Run(); // Ensure all modules are loaded foreach (var module in moduleCatalog.Modules.OfType <ManifestModuleInfo>().Where(x => x.State == ModuleState.NotStarted)) { manager.LoadModule(module.ModuleName); // Register API controller from modules mvcBuilder.AddApplicationPart(module.Assembly); } services.AddSingleton(moduleCatalog); return(services); }
public static void InitMiriwork(IMvcBuilder mvcbuilder, IServiceCollection services, MiriworkConfiguration miriworkConfiguration, Type[] boundedContextTypes) { // add memorycache to cache http-requests services.AddMemoryCache(); // add the assembly as an application part so that MiriController can be found mvcbuilder.AddApplicationPart(Assembly.GetExecutingAssembly()); // create and register the Miriwork-classes services.AddHttpContextAccessor(); var tempServiceProvider = services.BuildServiceProvider(); var boundedContextManager = CreateBoundedContextManager(services, miriworkConfiguration, boundedContextTypes); var requestIdFromHttpContextAccessor = CreateRequestIdFromHttpContextProvider(tempServiceProvider); var requestContextManager = CreateRequestContextAccessor(services, boundedContextManager, requestIdFromHttpContextAccessor, tempServiceProvider); AddMiriServiceBus(services, boundedContextManager, requestContextManager, tempServiceProvider); AddMiriModelBinderProviders(mvcbuilder, requestContextManager, tempServiceProvider); // register dependencies after registration of Miriwirk-classes RegisterDependenciesOfBoundedContexts(services, miriworkConfiguration, boundedContextManager); RegisterApplicationServicesOfBoundedContexts(services, miriworkConfiguration, boundedContextManager); }
public async Task <IActionResult> TestLoadPlugin() { var path = Path.Combine(pluginManagers.GetBasePluginsPath(), "Brochure.Authority", "plugin.config"); var p = await pluginLoader.LoadPlugin(path); if (!(p is Plugins plugin)) { return new ContentResult() { Content = "bbb" } } ; var startConfigs = reflectorUtil.GetObjectOfBase <IStarupConfigure>(plugin.Assembly); // var context = new PluginMiddleContext(app.ServiceProvider, plugin.Key); // plugin.Context.Services.Add(context); foreach (var item in startConfigs) { item.Configure(plugin.Key, applicationBuilder); } mvcBuilder.AddApplicationPart(plugin.Assembly); PluginActionDescriptorChangeProvider.Instance.HasChanged = true; PluginActionDescriptorChangeProvider.Instance.TokenSource.Cancel(); return(new ContentResult() { Content = "aaa" }); }
public static IMvcBuilder LoadApplicationAssembly(this IMvcBuilder builder) { string contentderPackagePath = Path.Combine(AppContext.BaseDirectory, FolderName.WWWWroot, FolderName.ContentderPackages); if (Directory.Exists(contentderPackagePath)) { string[] packages = Directory.GetDirectories(contentderPackagePath); for (int i = 0, length = packages.Length; i < length; i++) { string dllPath = Path.Combine(packages[i], "dll"); if (Directory.Exists(dllPath)) { string[] dlls = Directory.GetFiles(dllPath, "*.dll"); for (int j = 0, len = dlls.Length; j < len; j++) { string filePath = dlls[j]; string fileName = Path.GetFileName(filePath); var destFilePath = Path.Combine(AppContext.BaseDirectory, fileName); if (!File.Exists(destFilePath)) { File.Copy(filePath, destFilePath); } builder.AddApplicationPart( AssemblyLoadContext.Default.LoadFromAssemblyPath( destFilePath )); } } } } return(builder); }
public static IServiceCollection AddModules(this IServiceCollection services, IMvcBuilder mvcBuilder, Action <LocalStorageModuleCatalogOptions> setupAction = null) { services.AddSingleton(services); services.AddSingleton <IModuleInitializer, ModuleInitializer>(); // Cannot inject IHostingEnvironment to LoadContextAssemblyResolver as IsDevelopment() is an extension method (means static) and cannot be mocked by Moq in tests services.AddSingleton <IAssemblyResolver, LoadContextAssemblyResolver>(provider => new LoadContextAssemblyResolver(provider.GetService <ILogger <LoadContextAssemblyResolver> >(), provider.GetService <IHostingEnvironment>().IsDevelopment())); services.AddSingleton <IModuleManager, ModuleManager>(); services.AddSingleton <ILocalModuleCatalog, LocalStorageModuleCatalog>(); services.AddSingleton <IModuleCatalog>(provider => provider.GetService <ILocalModuleCatalog>()); if (setupAction != null) { services.Configure(setupAction); } var providerSnapshot = services.BuildServiceProvider(); var manager = providerSnapshot.GetRequiredService <IModuleManager>(); var moduleCatalog = providerSnapshot.GetRequiredService <ILocalModuleCatalog>(); manager.Run(); // Ensure all modules are loaded foreach (var module in moduleCatalog.Modules.OfType <ManifestModuleInfo>().Where(x => x.State == ModuleState.NotStarted).ToArray()) { manager.LoadModule(module.ModuleName); // Register API controller from modules mvcBuilder.AddApplicationPart(module.Assembly); } services.AddSingleton(moduleCatalog); return(services); }
/*========================================================================================================================== | EXTENSION: ADD TOPIC SUPPORT (IMVCBUILDER) \-------------------------------------------------------------------------------------------------------------------------*/ /// <summary> /// Configures the Razor engine to include OnTopic view locations via the <see cref="TopicViewLocationExpander"/>. /// </summary> public static IMvcBuilder AddTopicSupport(this IMvcBuilder services) { /*------------------------------------------------------------------------------------------------------------------------ | Validate parameters \-----------------------------------------------------------------------------------------------------------------------*/ Contract.Requires(services, nameof(services)); /*------------------------------------------------------------------------------------------------------------------------ | Register services \-----------------------------------------------------------------------------------------------------------------------*/ services.Services.TryAddSingleton<IActionResultExecutor<TopicViewResult>, TopicViewResultExecutor>(); services.Services.TryAddSingleton<TopicRouteValueTransformer>(); /*------------------------------------------------------------------------------------------------------------------------ | Configure services \-----------------------------------------------------------------------------------------------------------------------*/ services.AddRazorOptions(o => { o.ViewLocationExpanders.Add(new TopicViewLocationExpander()); }); /*------------------------------------------------------------------------------------------------------------------------ | Register local controllers \-----------------------------------------------------------------------------------------------------------------------*/ //Add Topic assembly into scope services.AddApplicationPart(typeof(TopicController).Assembly); /*------------------------------------------------------------------------------------------------------------------------ | Return services for fluent API \-----------------------------------------------------------------------------------------------------------------------*/ return services; }
public static IServiceCollection AddUmaWebsite(this IServiceCollection services, IMvcBuilder mvcBuilder, UmaWebsiteOptions umaWebsiteOptions) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (mvcBuilder == null) { throw new ArgumentNullException(nameof(mvcBuilder)); } if (umaWebsiteOptions == null) { throw new ArgumentNullException(nameof(umaWebsiteOptions)); } var assembly = typeof(HomeController).Assembly; var embeddedFileProvider = new EmbeddedFileProvider(assembly); services.Configure <RazorViewEngineOptions>(options => { options.FileProviders.Add(embeddedFileProvider); }); mvcBuilder.AddApplicationPart(assembly); services.AddSingleton(umaWebsiteOptions.Authentication); services.AddSimpleIdServerUmaWebsite(umaWebsiteOptions.Configuration.ResourceSet, null, umaWebsiteOptions.Configuration.Policies); return(services); }
/// <summary> /// Registers API Controllers implementing the Open Service Broker API. /// </summary> /// <remarks> /// Make sure to also register your implementations of: /// <see cref="ICatalogService"/>, /// <see cref="IServiceInstanceBlocking"/> or <see cref="IServiceInstanceDeferred"/>, /// optionally <see cref="IServiceBindingBlocking"/> or <see cref="IServiceBindingDeferred"/>. /// </remarks> public static IMvcBuilder AddOpenServiceBroker(this IMvcBuilder builder) { builder.AddApplicationPart(typeof(CatalogController).Assembly); builder.AddNewtonsoftJson(); return(builder); }
public static IServiceCollection AddApplicationAuth(this IServiceCollection services, IMvcBuilder mvcBuilder, IConfiguration configuration) { // Controllers mvcBuilder.AddApplicationPart(typeof(AuthController).GetTypeInfo().Assembly); //------------------------- Commands // ForgotPassword services.AddScoped <IForgotPasswordService, ForgotPasswordService>(); services.Configure <ResetPasswordPageInfo>(configuration.GetSection("ResetPasswordPageInfo")); // ResetPassword services.AddScoped <IResetPasswordService, ResetPasswordService>(); //------------------------- Queries // Common services.AddScoped <ICommonService, CommonService>(); services.AddScoped <ICommonRepository, CommonRepository>(); // LoginUser services.AddScoped <ILoginUserService, LoginUserService>(); // GetCurrentLoggedUser services.AddScoped <IGetCurrentLoggedUserService, GetCurrentLoggedUserService>(); // CheckPasswordToken services.AddScoped <ICheckPasswordTokenService, CheckPasswordTokenService>(); // RefreshToken services.AddScoped <IRefreshTokenService, RefreshTokenService>(); services.AddScoped <IRefreshTokenRepository, RefreshTokenRepository>(); return(services); }
private void AddMvc(IServiceCollection services) { IMvcBuilder mvcBuilder = services.AddMvc(); foreach (Assembly assembly in ExtensionManager.Assemblies) { mvcBuilder.AddApplicationPart(assembly); } mvcBuilder.AddRazorOptions( o => { foreach (Assembly assembly in ExtensionManager.Assemblies) { o.FileProviders.Add(new EmbeddedFileProvider(assembly, assembly.GetName().Name)); } } ); foreach (Action <IMvcBuilder> prioritizedAddMvcAction in this.GetPrioritizedAddMvcActions()) { this.logger.LogInformation("Executing prioritized AddMvc action '{0}' of {1}", this.GetActionMethodInfo(prioritizedAddMvcAction)); prioritizedAddMvcAction(mvcBuilder); } }
public static IMvcBuilder AddModules(this IMvcBuilder mvcBuilder) { var moduleManager = ModuleManager.GetInstance(); var services = mvcBuilder.Services; var serviceProvider = services.BuildServiceProvider(); var modules = moduleManager.Modules; using (var serviceScope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetService <CoreInDbContext>(); var isMigration = dbContext.Database.GetPendingMigrations(); if (!isMigration.Any()) { foreach (var module in modules) { mvcBuilder.AddApplicationPart(module.Assembly); // Register dependency in modules var a = module.Assembly.GetTypes(); var b = a.Where(x => typeof(IModuleInitializer).IsAssignableFrom(x)); var moduleInitializerType = b.FirstOrDefault(); if (moduleInitializerType != null && moduleInitializerType != typeof(IModuleInitializer)) { var moduleInitializer = (IModuleInitializer)Activator.CreateInstance(moduleInitializerType); moduleInitializer.Init(services); } } } } return(mvcBuilder); }