-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
65 lines (53 loc) · 1.99 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using managemoney.Models;
using managemoney.Helpers;
using managemoney.Repositorios;
using managemoney.Models.Interfaces;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using managemoney.Models.ViewModels.Lancamento;
using managemoney.Filters;
var builder = WebApplication.CreateBuilder(args);
var stringDeConexao = OperatingSystem.IsLinux() ? builder.Configuration.GetConnectionString("Default")
: builder.Configuration.GetConnectionString("Local");
builder.Services.AddDbContext<ApplicationContext>(o => {
o.UseSqlServer(stringDeConexao);
});
builder
.Services
.AddIdentity<UsuarioModel, IdentityRole>()
.AddEntityFrameworkStores<ApplicationContext>()
.AddDefaultTokenProviders();
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Services.AddAuthorization();
builder.Services.AddScoped<ContextoDoUsuario>();
builder.Services.AddScoped<IUsuarioRepository, UsuarioRepository>();
builder.Services.AddScoped<ILancamentoRepository, LancamentoRepository>();
builder.Services.AddScoped<ICategoriaRepository, CategoriaRepository>();
builder.Services.AddScoped<CadastroLancamentoViewModel>();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddCors();
builder.Services.AddMvc(opts =>
{
opts.Filters.Add(new CustomActionFilter());
opts.Filters.Add(typeof(CustomActionFilter));
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors(opcao => opcao.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseRouting();
app.UseAuthorization();
app.UseStaticFiles();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Inicio}/{action=Inicio}/{id?}");
endpoints.MapRazorPages();
});
app.Run();