// 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 IServiceProvider ConfigureServices(IServiceCollection services) { string sqlConnectionString = Configuration.GetConnectionString("DefaultConnection"); services.AddDbContext <BIMManagerContext>(options => options.UseMySql(sqlConnectionString, b => b.MigrationsAssembly("BIMManager.API"))); services.AddIdentity <IdentityUser, IdentityRole>() .AddEntityFrameworkStores <BIMManagerContext>() .AddDefaultTokenProviders(); // Register services services.AddScoped <JwtService>(); // CORS services.AddCors(); // Add JWT Auth JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); services .AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(config => { config.RequireHttpsMetadata = false; config.SaveToken = true; config.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters { ValidIssuer = Configuration["JwtIssuer"], ValidAudience = Configuration["JwtIssuer"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtKey"])), ClockSkew = TimeSpan.Zero }; }); // Add MVC services to the services container. services.AddMvc() .AddJsonOptions(opts => { // Force Camel Case to JSON opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); opts.SerializerSettings.Converters.Add(new StringEnumConverter { }); opts.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); services.AddOptions(); var serviceProvider = services.BuildServiceProvider(); BIMManagerContext dbContext = serviceProvider.GetService <BIMManagerContext>(); DbInitializer.Initialize(dbContext); return(serviceProvider); }
public AuthController(UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager, IConfiguration configuration, JwtService jwtService, BIMManagerContext managerContext) { _userManager = userManager; _signInManager = signInManager; _configuration = configuration; _jwtService = jwtService; _dbContext = managerContext; }
public ProjectController(BIMManagerContext context) { _dbContext = context; }
public static void Initialize(BIMManagerContext context) { _context = context; Initialize(); }