// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { //if (env.IsDevelopment()) //{ // app.UseDeveloperExceptionPage(); //} //else //{ //app.UseExceptionHandler("/Home/Error"); //// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. //app.UseHsts(); //} ServiceActivator.Configure(app.ApplicationServices); app.UseExceptionHandler("/Error/Http500"); //500 numaralý kod çalýþtýrma hatalarý için app.UseHsts(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } ServiceActivator.Configure(app.ApplicationServices); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); }
public static void AddTokenRepositoryV2(this IServiceCollection services, string server, int maxRateLimit, TimeSpan restDuration, TimeSpan watchDuration, int maxForDuration = int.MinValue, bool blocking = false) { var apiLimitsConfig = new ApiLimitsConfig(); apiLimitsConfig.Setup(server, maxRateLimit, restDuration, watchDuration, maxForDuration, blocking); var sp = services.BuildServiceProvider(); var logFactory = sp.GetRequiredService <ILoggerFactory>(); if (maxForDuration > 0 && maxRateLimit > 0) //injects only 2 ITokenRepository { services.AddSingleton <IGrantToken>(sevs => { return(new MultiTokenApiGateway(apiLimitsConfig, logFactory)); }); } else if (maxForDuration > 0 || maxRateLimit > 0) //injects only 1 ITokenRepository { services.AddSingleton <IGrantToken>(sevs => { return(new SingleTokenApiGateway(apiLimitsConfig, logFactory)); }); } else { throw new InvalidOperationException("ITokenRepository cannot be determined, make sure configuration is valid to inject at least 1 ITokenRepository."); } ServiceActivator.Configure(sp);//Only for using Fody Attributes }
/// <summary> /// Configure the application builder /// </summary> /// <param name="app">IApplicationBuilder</param> /// <param name="env">IWebHostEnvironment</param> public static void Configure(IApplicationBuilder app, IWebHostEnvironment env) { _ = app ?? throw new ArgumentNullException(nameof(app)); ServiceActivator.Configure(app.ApplicationServices); // log http responses to the console // this should be first as it "wraps" all requests if (App.AppLogLevel != LogLevel.None) { app.UseLogger(new LoggerOptions { Log2xx = App.AppLogLevel <= LogLevel.Information, Log3xx = App.AppLogLevel <= LogLevel.Information, Log4xx = App.AppLogLevel <= LogLevel.Warning, Log5xx = true, }); } // differences based on dev or prod if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseResponseCaching(); app.UseStaticFiles(); // use routing app.UseRouting(); // map the controllers app.UseEndpoints(ep => { ep.MapControllers(); }); // rewrite root to /index.html app.UseSwaggerRoot(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint(Constants.SwaggerPath, Constants.SwaggerTitle); c.RoutePrefix = string.Empty; }); // use the robots middleware to handle /robots*.txt requests app.UseRobots(); // use the version middleware to handle /version app.UseVersion(); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger <Startup> logger) { // Configure ServiceActivator ServiceActivator.Configure(app.ApplicationServices); // Get custom HttpClientFactory and configure Flurl to use it var factory = (PollyHttpClientFactory)app.ApplicationServices.GetService(typeof(PollyHttpClientFactory)); FlurlHttp.Configure((settings) => { settings.HttpClientFactory = factory; settings.OnErrorAsync = call => { logger.LogError($"Call failed: {call.Exception}"); return(Task.CompletedTask); }; }); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1.0/swagger.json", $"{API_NAME} v1.0"); c.RoutePrefix = string.Empty; }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // Read more: https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl?view=aspnetcore-3.1&tabs=visual-studio // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseDefaultFiles(); app.UseStaticFiles(); // Global Exception handling middleware app.UseMiddleware <ExceptionHandling>(); // Request/Response logging middleware app.UseMiddleware <ApiLogging>(); app.UseMiddleware <RedoxDataModelDispatcher>(); app.UseRouting(); app.UseCors("EnableCORS"); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, Seeder seeder) { ServiceActivator.Configure(app.ApplicationServices); if (_env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint(SwaggerConfiguration.SwaggerEndPointURL, SwaggerConfiguration.SwaggerEndPointName); }); } else { app.UseHsts(); } seeder.Seed().Wait(); app.UseMiddleware <ExceptionMiddleware>(); app.UseAuthentication(); app.UseHttpsRedirection(); app.UseRouting(); List <string> origins = new List <string> { "http://localhost:4200", "https://localhost:4200", "http://localhost:4300", "http://localhost:4500" }; app.UseCors(options => { options.WithOrigins(origins.ToArray()).AllowAnyMethod().AllowCredentials().AllowAnyHeader().SetIsOriginAllowed((host) => true); }); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISyncManager sync) { ServiceActivator.Configure(app.ApplicationServices); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebAssemblyDebugging(); app.UseForwardedHeaders(); } else { app.UseForwardedHeaders(); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } // execute any IServerStartup logic app.ConfigureOqtaneAssemblies(env); // Allow oqtane localization middleware app.UseOqtaneLocalization(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseTenantResolution(); app.UseBlazorFrameworkFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); if (_useSwagger) { app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/" + Constants.Version + "/swagger.json", Constants.PackageId + " " + Constants.Version); }); } app.UseEndpoints(endpoints => { endpoints.MapBlazorHub(); endpoints.MapControllers(); endpoints.MapFallbackToPage("/_Host"); }); // create a global sync event to identify server application startup sync.AddSyncEvent(-1, "Application", -1, true); }
public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add <App>("app"); var httpClient = new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }; builder.Services.AddSingleton(httpClient); builder.Services.AddOptions(); // Register localization services builder.Services.AddLocalization(options => options.ResourcesPath = "Resources"); // register auth services builder.Services.AddOqtaneAuthorization(); // register scoped core services builder.Services.AddOqtaneScopedServices(); await LoadClientAssemblies(httpClient); var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies(); foreach (var assembly in assemblies) { // dynamically register module services RegisterModuleServices(assembly, builder.Services); // register client startup services RegisterClientStartups(assembly, builder.Services); } var host = builder.Build(); await SetCultureFromLocalizationCookie(host.Services); ServiceActivator.Configure(host.Services); await host.RunAsync(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { ServiceActivator.Configure(app.ApplicationServices); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebAssemblyDebugging(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } // to allow install middleware it should be moved up app.ConfigureOqtaneAssemblies(env); // Allow oqtane localization middleware app.UseOqtaneLocalization(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseBlazorFrameworkFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); if (_useSwagger) { app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Oqtane V1"); }); } app.UseEndpoints(endpoints => { endpoints.MapBlazorHub(); endpoints.MapControllers(); endpoints.MapFallbackToPage("/_Host"); }); }
public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add <App>("app"); HttpClient httpClient = new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }; builder.Services.AddSingleton(httpClient); builder.Services.AddOptions(); // Register localization services builder.Services.AddLocalization(options => options.ResourcesPath = "Resources"); // register auth services builder.Services.AddAuthorizationCore(); builder.Services.AddScoped <IdentityAuthenticationStateProvider>(); builder.Services.AddScoped <AuthenticationStateProvider>(s => s.GetRequiredService <IdentityAuthenticationStateProvider>()); // register scoped core services builder.Services.AddScoped <SiteState>(); builder.Services.AddScoped <IInstallationService, InstallationService>(); builder.Services.AddScoped <IModuleDefinitionService, ModuleDefinitionService>(); builder.Services.AddScoped <IThemeService, ThemeService>(); builder.Services.AddScoped <IAliasService, AliasService>(); builder.Services.AddScoped <ITenantService, TenantService>(); builder.Services.AddScoped <ISiteService, SiteService>(); builder.Services.AddScoped <IPageService, PageService>(); builder.Services.AddScoped <IModuleService, ModuleService>(); builder.Services.AddScoped <IPageModuleService, PageModuleService>(); builder.Services.AddScoped <IUserService, UserService>(); builder.Services.AddScoped <IProfileService, ProfileService>(); builder.Services.AddScoped <IRoleService, RoleService>(); builder.Services.AddScoped <IUserRoleService, UserRoleService>(); builder.Services.AddScoped <ISettingService, SettingService>(); builder.Services.AddScoped <IPackageService, PackageService>(); builder.Services.AddScoped <ILogService, LogService>(); builder.Services.AddScoped <IJobService, JobService>(); builder.Services.AddScoped <IJobLogService, JobLogService>(); builder.Services.AddScoped <INotificationService, NotificationService>(); builder.Services.AddScoped <IFolderService, FolderService>(); builder.Services.AddScoped <IFileService, FileService>(); builder.Services.AddScoped <ISiteTemplateService, SiteTemplateService>(); builder.Services.AddScoped <ISqlService, SqlService>(); builder.Services.AddScoped <ISystemService, SystemService>(); builder.Services.AddScoped <ILocalizationService, LocalizationService>(); builder.Services.AddScoped <ILanguageService, LanguageService>(); await LoadClientAssemblies(httpClient); var assemblies = AppDomain.CurrentDomain.GetOqtaneAssemblies(); foreach (var assembly in assemblies) { // dynamically register module services var implementationTypes = assembly.GetInterfaces <IService>(); foreach (var implementationType in implementationTypes) { if (implementationType.AssemblyQualifiedName != null) { var serviceType = Type.GetType(implementationType.AssemblyQualifiedName.Replace(implementationType.Name, $"I{implementationType.Name}")); builder.Services.AddScoped(serviceType ?? implementationType, implementationType); } } // register client startup services var startUps = assembly.GetInstances <IClientStartup>(); foreach (var startup in startUps) { startup.ConfigureServices(builder.Services); } } var host = builder.Build(); var jsRuntime = host.Services.GetRequiredService <IJSRuntime>(); var interop = new Interop(jsRuntime); var localizationCookie = await interop.GetCookie(CookieRequestCultureProvider.DefaultCookieName); var culture = CookieRequestCultureProvider.ParseCookieValue(localizationCookie).UICultures[0].Value; var localizationService = host.Services.GetRequiredService <ILocalizationService>(); var cultures = await localizationService.GetCulturesAsync(); if (culture == null || !cultures.Any(c => c.Name.Equals(culture, StringComparison.OrdinalIgnoreCase))) { culture = cultures.Single(c => c.IsDefault).Name; } SetCulture(culture); ServiceActivator.Configure(host.Services); await host.RunAsync(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { // Register localization services services.AddLocalization(options => options.ResourcesPath = "Resources"); services.AddServerSideBlazor(); // setup HttpClient for server side in a client side compatible fashion ( with auth cookie ) if (!services.Any(x => x.ServiceType == typeof(HttpClient))) { services.AddScoped(s => { // creating the URI helper needs to wait until the JS Runtime is initialized, so defer it. var navigationManager = s.GetRequiredService <NavigationManager>(); var httpContextAccessor = s.GetRequiredService <IHttpContextAccessor>(); var authToken = httpContextAccessor.HttpContext.Request.Cookies[".AspNetCore.Identity.Application"]; var client = new HttpClient(new HttpClientHandler { UseCookies = false }); if (authToken != null) { client.DefaultRequestHeaders.Add("Cookie", ".AspNetCore.Identity.Application=" + authToken); } client.BaseAddress = new Uri(navigationManager.Uri); return(client); }); } // register custom authorization policies services.AddAuthorizationCore(options => { options.AddPolicy("ViewPage", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Page, PermissionNames.View))); options.AddPolicy("EditPage", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Page, PermissionNames.Edit))); options.AddPolicy("ViewModule", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Module, PermissionNames.View))); options.AddPolicy("EditModule", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Module, PermissionNames.Edit))); options.AddPolicy("ViewFolder", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.View))); options.AddPolicy("EditFolder", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.Edit))); options.AddPolicy("ListFolder", policy => policy.Requirements.Add(new PermissionRequirement(EntityNames.Folder, PermissionNames.Browse))); }); // register scoped core services services.AddScoped <SiteState>(); services.AddScoped <IAuthorizationHandler, PermissionHandler>(); services.AddScoped <IInstallationService, InstallationService>(); services.AddScoped <IModuleDefinitionService, ModuleDefinitionService>(); services.AddScoped <IThemeService, ThemeService>(); services.AddScoped <IAliasService, AliasService>(); services.AddScoped <ITenantService, TenantService>(); services.AddScoped <ISiteService, SiteService>(); services.AddScoped <IPageService, PageService>(); services.AddScoped <IModuleService, ModuleService>(); services.AddScoped <IPageModuleService, PageModuleService>(); services.AddScoped <IUserService, UserService>(); services.AddScoped <IProfileService, ProfileService>(); services.AddScoped <IRoleService, RoleService>(); services.AddScoped <IUserRoleService, UserRoleService>(); services.AddScoped <ISettingService, SettingService>(); services.AddScoped <IPackageService, PackageService>(); services.AddScoped <ILogService, LogService>(); services.AddScoped <IJobService, JobService>(); services.AddScoped <IJobLogService, JobLogService>(); services.AddScoped <INotificationService, NotificationService>(); services.AddScoped <IFolderService, FolderService>(); services.AddScoped <IFileService, FileService>(); services.AddScoped <ISiteTemplateService, SiteTemplateService>(); services.AddScoped <ISqlService, SqlService>(); services.AddScoped <ISystemService, SystemService>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddDbContext <MasterDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection") .Replace("|DataDirectory|", AppDomain.CurrentDomain.GetData("DataDirectory")?.ToString()) )); services.AddDbContext <TenantDBContext>(options => { }); services.AddIdentityCore <IdentityUser>(options => { }) .AddEntityFrameworkStores <TenantDBContext>() .AddSignInManager() .AddDefaultTokenProviders(); services.Configure <LocalizationOptions>(Configuration.GetSection("Localization")); services.Configure <IdentityOptions>(options => { // Password settings options.Password.RequireDigit = false; options.Password.RequiredLength = 6; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; // Lockout settings options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); options.Lockout.MaxFailedAccessAttempts = 10; options.Lockout.AllowedForNewUsers = true; // User settings options.User.RequireUniqueEmail = false; }); services.AddAuthentication(IdentityConstants.ApplicationScheme) .AddCookie(IdentityConstants.ApplicationScheme); services.ConfigureApplicationCookie(options => { options.Cookie.HttpOnly = false; options.Events.OnRedirectToLogin = context => { context.Response.StatusCode = 401; return(Task.CompletedTask); }; }); // register custom claims principal factory for role claims services.AddTransient <IUserClaimsPrincipalFactory <IdentityUser>, ClaimsPrincipalFactory <IdentityUser> >(); // register singleton scoped core services services.AddSingleton(Configuration); services.AddSingleton <IInstallationManager, InstallationManager>(); services.AddSingleton <ISyncManager, SyncManager>(); services.AddSingleton <IDatabaseManager, DatabaseManager>(); // install any modules or themes ( this needs to occur BEFORE the assemblies are loaded into the app domain ) InstallationManager.InstallPackages("Modules,Themes", _webRoot); // register transient scoped core services services.AddTransient <IModuleDefinitionRepository, ModuleDefinitionRepository>(); services.AddTransient <IThemeRepository, ThemeRepository>(); services.AddTransient <IUserPermissions, UserPermissions>(); services.AddTransient <ITenantResolver, TenantResolver>(); services.AddTransient <IAliasRepository, AliasRepository>(); services.AddTransient <ITenantRepository, TenantRepository>(); services.AddTransient <ISiteRepository, SiteRepository>(); services.AddTransient <IPageRepository, PageRepository>(); services.AddTransient <IModuleRepository, ModuleRepository>(); services.AddTransient <IPageModuleRepository, PageModuleRepository>(); services.AddTransient <IUserRepository, UserRepository>(); services.AddTransient <IProfileRepository, ProfileRepository>(); services.AddTransient <IRoleRepository, RoleRepository>(); services.AddTransient <IUserRoleRepository, UserRoleRepository>(); services.AddTransient <IPermissionRepository, PermissionRepository>(); services.AddTransient <ISettingRepository, SettingRepository>(); services.AddTransient <ILogRepository, LogRepository>(); services.AddTransient <ILogManager, LogManager>(); services.AddTransient <ILocalizationManager, LocalizationManager>(); services.AddTransient <IJobRepository, JobRepository>(); services.AddTransient <IJobLogRepository, JobLogRepository>(); services.AddTransient <INotificationRepository, NotificationRepository>(); services.AddTransient <IFolderRepository, FolderRepository>(); services.AddTransient <IFileRepository, FileRepository>(); services.AddTransient <ISiteTemplateRepository, SiteTemplateRepository>(); services.AddTransient <ISqlRepository, SqlRepository>(); services.AddTransient <IUpgradeManager, UpgradeManager>(); // TODO: Check if there's a better way instead of building service provider ServiceActivator.Configure(services.BuildServiceProvider()); // load the external assemblies into the app domain, install services services.AddOqtane(_runtime); services.AddMvc() .AddNewtonsoftJson() .AddOqtaneApplicationParts() // register any Controllers from custom modules .ConfigureOqtaneMvc(); // any additional configuration from IStart classes. if (_useSwagger) { services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Oqtane", Version = "v1" }); }); } }
public static IServiceProvider AddLite(this IServiceCollection services) { Throw.IfNull(services); // utils services.AddSingleton <IUtil, Util>(); services.AddSingleton <IDiskUtils, DiskUtils>(); services.AddSingleton <IDicomUtil, DicomUtil>(); services.AddSingleton <IDcmtkUtil, DcmtkUtil>(); services.AddSingleton <ICrypto, Crypto>(); // common services.AddSingleton <ILoggerManager, LoggerManager>(); services.AddSingleton <IScriptService, ScriptService>(); services.AddSingleton <IProfileStorage, ProfileStorage>(); services.AddSingleton <ILiteConfigService, LiteConfigService>(); services.AddSingleton <IConnectionFinder, ConnectionFinder>(); services.AddSingleton <ILitePurgeService, LitePurgeService>(); services.AddSingleton <IX509CertificateService, X509CertificateService>(); services.AddSingleton <IRoutedItemLoader, RoutedItemLoader>(); services.AddTransient <ILiteHttpClient, LiteHttpClient>(); services.AddTransient <IConfigurationLoader, ConfigurationLoader>(); services.AddTransient <IDuplicatesDetectionService, DuplicatesDetectionService>(); // routing features services.AddTransient <IEnqueueCacheService, EnqueueCacheService>(); services.AddTransient <IEnqueueService, EnqueueService>(); services.AddTransient <IEnqueueBlockingCollectionService, EnqueueBlockingCollectionService>(); services.AddTransient <IDequeueService, DequeueService>(); services.AddTransient <IDequeueBlockingCollectionService, DequeueBlockingCollectionService>(); services.AddTransient <IDequeueCacheService, DequeueCacheService>(); services.AddTransient <ITranslateService, TranslateService>(); services.AddTransient <IAgeAtExamService, AgeAtExamService>(); services.AddTransient <IRoutedItemManager, RoutedItemManager>(); // rules manager services.AddTransient <IRulesEvalService, RulesEvalService>(); services.AddTransient <IRunPreProcessToConnectionScriptsService, RunPreProcessToConnectionScriptsService>(); services.AddTransient <IRunPreProcessFromConnectionScriptsService, RunPreProcessFromConnectionScriptsService>(); services.AddTransient <IRunPostProcessFromConnectionScriptsService, RunPostProcessFromConnectionScriptsService>(); services.AddTransient <IRunPostProcessToConnectionScriptsService, RunPostProcessToConnectionScriptsService>(); services.AddTransient <IDoTagsMatchService, DoTagsMatchService>(); services.AddTransient <IDoesRuleMatchService, DoesRuleMatchService>(); services.AddTransient <ICheckAndDelayOnWaitConditionsService, CheckAndDelayOnWaitConditionsService>(); services.AddTransient <IRulesManager, RulesManager>(); // profile features services.AddTransient <IProfileConnectionsInitializer, ProfileConnectionsInitializer>(); services.AddTransient <ICloudProfileLoaderService, CloudProfileLoaderService>(); services.AddTransient <ICloudProfileWriterService, CloudProfileWriterService>(); services.AddTransient <IProfileJsonHelper, ProfileJsonHelper>(); services.AddTransient <IProfileLoaderService, ProfileLoaderService>(); services.AddTransient <IProfileValidator, ProfileValidator>(); services.AddTransient <IProfileWriter, ProfileWriter>(); services.AddTransient <IFileProfileWriter, FileProfileWriter>(); services.AddTransient <IProfileManager, ProfileManager>(); services.AddTransient <IProfileMerger, ProfileMerger>(); // studies services.AddTransient <IStudyManager, StudyManager>(); services.AddTransient <IStudiesDownloadManager, StudiesDownloadManager>(); // connection manager factory services.AddTransient <IConnectionManagerFactory, ConnectionManagerFactory>(); // cache services.AddTransient <IConnectionCacheResponseService, ConnectionCacheResponseService>(); services.AddTransient <IConnectionToRulesManagerAdapter, ConnectionToRulesManagerAdapter>(); // connection managers services.AddTransient <ILifeImageCloudConnectionManager, LifeImageCloudConnectionManager>(); services.AddTransient <IDicomConnectionManager, DicomConnectionManager>(); services.AddTransient <IHl7ConnectionManager, Hl7ConnectionManager>(); services.AddTransient <IFileConnectionManager, FileConnectionManager>(); services.AddTransient <IDcmtkConnectionManager, DcmtkConnectionManager>(); services.AddTransient <ILiteConnectionManager, LiteConnectionManager>(); // cloud features services.AddTransient <ICloudPingService, CloudPingService>(); services.AddTransient <ICloudKeepAliveService, CloudKeepAliveService>(); services.AddTransient <ICloudDownloadService, CloudDownloadService>(); services.AddTransient <ICloudUploadService, CloudUploadService>(); services.AddTransient <ICloudShareDestinationsService, CloudShareDestinationsService>(); services.AddTransient <ICloudLoginService, CloudAuthenticationService>(); services.AddTransient <ICloudRegisterService, CloudRegisterService>(); services.AddTransient <ICloudLogoutService, CloudAuthenticationService>(); services.AddTransient <IStowAsMultiPartCloudService, StowAsMultiPartCloudService>(); services.AddTransient <ISendFromCloudToHl7Service, SendFromCloudToHl7Service>(); services.AddTransient <IPostResponseCloudService, PostResponseCloudService>(); services.AddTransient <IPostCompletionCloudService, PostCompletionCloudService>(); services.AddTransient <ISendToCloudService, SendToCloudService>(); services.AddTransient <ICloudAgentTaskLoader, CloudAgentTaskLoader>(); services.AddTransient <IMarkDownloadCompleteService, MarkDownloadCompleteService>(); services.AddTransient <ICloudConnectionCacheAccessor, CloudConnectionCacheAccessor>(); services.AddTransient <ICloudConnectionCacheManager, CloudConnectionCacheManager>(); // dicom features services.AddTransient <IDicomCFindCommand, DicomCFindCommand>(); services.AddTransient <IDicomCEchoCommand, DicomCEchoCommand>(); services.AddTransient <IDicomCMoveCommand, DicomCMoveCommand>(); services.AddTransient <IDicomCGetCommand, DicomCGetCommand>(); services.AddTransient <IDicomCStoreCommand, DicomCStoreCommand>(); services.AddTransient <ISendToDicomService, SendToDicomService>(); // HL7 features services.AddTransient <IAckMessageFormatter, AckMessageFormatter>(); services.AddTransient <IHl7ReaderService, Hl7ReaderService>(); services.AddTransient <ISendToHl7Service, SendToHl7Service>(); services.AddTransient <IHl7AcceptService, Hl7AcceptService>(); services.AddTransient <IHl7StartService, Hl7StartService>(); services.AddTransient <IHl7ClientsCleaner, Hl7ClientsCleaner>(); // dcmtk features services.AddTransient <IDcmtkConnectionInitializer, DcmtkConnectionInitializer>(); services.AddTransient <IDcmSendService, DcmSendService>(); services.AddTransient <IDcmtkDumpService, DcmtkDumpService>(); services.AddTransient <IDcmtkScanner, DcmtkScanner>(); services.AddTransient <IDicomizeService, DicomizeService>(); services.AddTransient <IEchoSCUService, EchoSCUService>(); services.AddTransient <IFindSCUService, FindSCUService>(); services.AddTransient <IMoveSCUService, MoveSCUService>(); services.AddTransient <IPushToDicomService, PushToDicomService>(); services.AddTransient <IStoreScpService, StoreScpService>(); // lite connection features services.AddTransient <ILiteUploadService, LiteUploadService>(); services.AddTransient <ILiteToEgsService, LiteToEgsService>(); services.AddTransient <ILitePresentAsResourceService, LitePresentAsResourceService>(); services.AddTransient <ILiteStoreService, LiteStoreService>(); services.AddTransient <IGetLiteReresourcesService, GetLiteReresourcesService>(); services.AddTransient <ILitePingService, LitePingService>(); services.AddTransient <ILiteDownloadService, LiteDownloadService>(); services.AddTransient <IDownloadViaHttpService, DownloadViaHttpService>(); services.AddTransient <IDeleteEGSResourceService, DeleteEGSResourceService>(); services.AddTransient <ILiteConnectionPurgeService, LiteConnectionPurgeService>(); services.AddTransient <IRegisterWithEGSService, RegisterWithEGSService>(); services.AddTransient <ISendToAllHubsService, SendToAllHubsService>(); // file manager features services.AddTransient <IFilePathFormatterHelper, FilePathFormatterHelper>(); services.AddTransient <ISendFileService, SendFileService>(); services.AddTransient <IFileExpanderService, FileExpanderService>(); services.AddTransient <IFileScanService, FileScanService>(); // infrastructure services.AddSingleton <ILiteTaskUpdater, LiteTaskUpdater>(); services.AddSingleton <ILITETask, LITETask>(); services.AddSingleton <ILiteEngine, LiteEngine>(); var serviceProvider = services.BuildServiceProvider(); ServiceActivator.Configure(serviceProvider); return(serviceProvider); }
public static async Task Main(string[] args) { var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add <App>("app"); HttpClient httpClient = new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }; builder.Services.AddSingleton(httpClient); builder.Services.AddOptions(); // Register localization services builder.Services.AddLocalization(options => options.ResourcesPath = "Resources"); // register auth services builder.Services.AddAuthorizationCore(); builder.Services.AddScoped <IdentityAuthenticationStateProvider>(); builder.Services.AddScoped <AuthenticationStateProvider>(s => s.GetRequiredService <IdentityAuthenticationStateProvider>()); // register scoped core services builder.Services.AddScoped <SiteState>(); builder.Services.AddScoped <IInstallationService, InstallationService>(); builder.Services.AddScoped <IModuleDefinitionService, ModuleDefinitionService>(); builder.Services.AddScoped <IThemeService, ThemeService>(); builder.Services.AddScoped <IAliasService, AliasService>(); builder.Services.AddScoped <ITenantService, TenantService>(); builder.Services.AddScoped <ISiteService, SiteService>(); builder.Services.AddScoped <IPageService, PageService>(); builder.Services.AddScoped <IModuleService, ModuleService>(); builder.Services.AddScoped <IPageModuleService, PageModuleService>(); builder.Services.AddScoped <IUserService, UserService>(); builder.Services.AddScoped <IProfileService, ProfileService>(); builder.Services.AddScoped <IRoleService, RoleService>(); builder.Services.AddScoped <IUserRoleService, UserRoleService>(); builder.Services.AddScoped <ISettingService, SettingService>(); builder.Services.AddScoped <IPackageService, PackageService>(); builder.Services.AddScoped <ILogService, LogService>(); builder.Services.AddScoped <IJobService, JobService>(); builder.Services.AddScoped <IJobLogService, JobLogService>(); builder.Services.AddScoped <INotificationService, NotificationService>(); builder.Services.AddScoped <IFolderService, FolderService>(); builder.Services.AddScoped <IFileService, FileService>(); builder.Services.AddScoped <ISiteTemplateService, SiteTemplateService>(); builder.Services.AddScoped <ISqlService, SqlService>(); builder.Services.AddScoped <ISystemService, SystemService>(); await LoadClientAssemblies(httpClient); // dynamically register module contexts and repository services Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblies) { var implementationTypes = assembly.GetTypes() .Where(item => item.GetInterfaces().Contains(typeof(IService))); foreach (Type implementationtype in implementationTypes) { Type servicetype = Type.GetType(implementationtype.AssemblyQualifiedName.Replace(implementationtype.Name, "I" + implementationtype.Name)); if (servicetype != null) { builder.Services.AddScoped(servicetype, implementationtype); // traditional service interface } else { builder.Services.AddScoped(implementationtype, implementationtype); // no interface defined for service } } assembly.GetInstances <IClientStartup>() .ToList() .ForEach(x => x.ConfigureServices(builder.Services)); } var host = builder.Build(); ServiceActivator.Configure(host.Services); await host.RunAsync(); }
public static ISundayServicesConfiguration LoadServices(this ISundayServicesConfiguration serviceConf) { var services = serviceConf.Services; var assemblies = AssemblyHelper.GetAllAssemblies(x => (!x.StartsWith("Microsoft") && !x.StartsWith("System")) && (x.Contains("Sunday") || x.Contains("Plugin"))).ToArray(); var types = AssemblyHelper.GetClassesWithAttribute(assemblies, typeof(ServiceTypeOfAttribute)); foreach (var type in types) { var attr = ((ServiceTypeOfAttribute)type.GetCustomAttribute(typeof(ServiceTypeOfAttribute))); var parentType = attr.ServiceType; var scope = attr.LifetimeScope; switch (scope) { case LifetimeScope.Transient: if (parentType == type) { services.AddTransient(type); } else { services.AddTransient(parentType, type); } break; case LifetimeScope.Singleton: if (parentType == type) { services.AddSingleton(type); } else { services.AddSingleton(parentType, type); } break; case LifetimeScope.PerRequest: if (parentType == type) { services.AddScoped(type); } else { services.AddScoped(parentType, type); } break; default: if (parentType == type) { services.AddTransient(type); } else { services.AddTransient(parentType, type); } break; } } var serviceProvider = services.BuildServiceProvider(); ServiceActivator.Configure(serviceProvider); return(serviceConf); }
/// <summary> /// Configure service /// </summary> /// <param name="app">Application</param> /// <param name="env">Enviroment</param> /// <param name="loggerFactory">Logger factory</param> public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); if (Environment.GetEnvironmentVariable("ASPNETCORE_RUNTYPE_ENVIRONMENT") == "Docker") { loggerFactory.AddLog4Net("log4netDocker.config"); } else { loggerFactory.AddLog4Net("log4net.config"); } ServiceActivator.Configure(app.ApplicationServices); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseIpRateLimiting(); app.UseStatusCodePages(); app.UseStaticFiles(); app.UseSwagger(swagger => { swagger.PreSerializeFilters.Add((swaggerDoc, httpReq) => { swaggerDoc.Servers = new List <OpenApiServer> { new OpenApiServer { Url = $"{SwaggerConfiguration.Host}/{SwaggerConfiguration.HostPostfix}" } }; }); swagger.RouteTemplate = $"/{SwaggerConfiguration.PrefixDocPath}/{{documentname}}/swagger.json"; }); app.UseSwaggerUI(swaggerUI => { string hostPrefix = string.IsNullOrEmpty(SwaggerConfiguration.HostPostfix) ? string.Empty : "/" + SwaggerConfiguration.HostPostfix; swaggerUI.SwaggerEndpoint($"{hostPrefix}/{SwaggerConfiguration.PrefixDocPath}/{SwaggerConfiguration.Version}/swagger.json", SwaggerConfiguration.Title); swaggerUI.RoutePrefix = SwaggerConfiguration.PrefixDocPath; }); app.UseRouting(); app.UseMiddleware <ExceptionMiddleware>(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); app.UseCors(_allowSpecificOrigins); var option = new RewriteOptions(); option.AddRedirect("^$", $"{SwaggerConfiguration.HostPostfix}/swagger/index.html"); app.UseRewriter(option); }