123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Hosting;
- using System;
- using System.Collections.Generic;
- using VCommon.Ioc;
- using VCommon.Logging;
- using VCommon.VApplication;
- using VCommon.VOpenApi.VAspNetCore;
- using VCommon.VSwaggerUI;
- using VCommon.VSwaggerUI.VAspNetCore;
- using VCommonCoreExample.AppServices.Platform;
- using VCommonCoreExample.AppServices.Session;
- using VCommonCoreExample.AppServices.System.Roles;
- using VCommonCoreExample.AppServices.System.Users;
- using VCommonCoreExample.AppServices.UserProfiles;
- using VCommonCoreExample.Configuration;
- using VCommonCoreExample.EntityFrameworkCore;
- namespace VCommonCoreExample
- {
- public class Startup
- {
- private readonly IConfigurationRoot _appConfiguration;
- private readonly string _contentRootPath;
- public Startup(IWebHostEnvironment env)
- {
- _contentRootPath = env.ContentRootPath;
- _appConfiguration = env.GetAppConfiguration();
- }
- // 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)
- {
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
- {
- var dbg = false;
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- dbg = true;
- }
- Logger.Init(new VJsonFileLogger(enableAll: dbg));
- Logger.EnableDebugLevel = dbg;
- Logger.Info("Application Init");
- AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
- {
- Logger.Fatal("AppDomain.CurrentDomain.UnhandledException", e);
- };
- var connectionString = _appConfiguration.GetConnectionString(ProjectConst.ConnectionStringName);
- var dbContextOptionsBuilder = new DbContextOptionsBuilder<ExampleDbContext>();
- ExampleDbContextConfig.Configure(dbContextOptionsBuilder, connectionString);
- var rootContainer = new IocManager();
- rootContainer.RegisterInstanceToContainer<IConfiguration>(_appConfiguration);
- rootContainer.RegisterInstanceToContainer(dbContextOptionsBuilder.Options);
- rootContainer.RegisterManually<VEmptySession>();
- if (dbg) app.UseSwaggerUiMiddleware(SwaggerUiResourceProvider.Version1);
- ApiMiddleware.Init(new Dictionary<string, Type>
- {
- {"Session",typeof(ISessionService) },
- {"SystemUser",typeof(IUserService) },
- {"SystemRole",typeof(IRoleService) },
- {"PlatformTenant",typeof(ITenantService) },
- {"UserProfile",typeof(IUserProfileService) },
- }, iocManager: rootContainer, docGen: dbg, isDebuggingEnabled: dbg);
- app.UseMiddleware<ApiMiddleware>();
- app.Use(async (context, next) =>
- {
- if (dbg && context.Request.Path.Value == "/")
- {
- context.Response.Redirect("/swagger/");
- }
- else await next();
- });
- Logger.Info("Application Init Done");
- }
- }
- }
|