private static void Startup(ExecutionParameters parameters) { LogConfig.Config(); TelemetryConfig.Config(); ExceptionHandling.Config(); IoCConfig.Config(); ConfigureDapper.Config(); GlobalizationConfig.Config(parameters.Get("culture")); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); IoCConfig.Config(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { #region Mapper var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new MappingProfile()); }); IMapper mapper = mappingConfig.CreateMapper(); services.AddSingleton(mapper); #endregion services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); IoCConfig.Config(services, Configuration); services.AddCors(options => { options.AddPolicy("AllowAll", builder => { builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); }); }); services.Configure <MvcOptions>(options => { options.Filters.Add(new CorsAuthorizationFilterFactory("AllowAll")); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Azure Dev Ops Project", Version = "v1", Description = "Exemplo de api para o projeto Azure Dev Ops", Contact = new Contact { Name = "Jonatas Marins" } }); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Singleton Configuration services.AddSingleton(_ => Configuration); services.AddCors(options => { options.AddPolicy("AllowAll", builder => { builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); }); }); //Add framework services. services.AddMvc() .AddJsonOptions(options => { options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; options.SerializerSettings.Formatting = Formatting.None; options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(); }); //IoC string connectionString = Configuration.GetConnectionString("DefaultConnection"); IoCConfig.Config(services, connectionString); //Parameters Config this.GetParameters(services); services.AddAuthentication( options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; } ); services.AddOptions(); services.AddApplicationInsightsTelemetry(Configuration); services.AddAutoMapper(); }
/// <summary> /// Creates the kernel that will manage your application. /// </summary> /// <returns>The created kernel.</returns> private static IKernel CreateKernel() { var kernel = new StandardKernel(); try { kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>(); IoCConfig.Config(kernel); return(kernel); } catch { kernel.Dispose(); throw; } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); IoCConfig.Config(services); services.AddSingleton(_ => Configuration); string connectionString = Configuration.GetConnectionString("ContatoConnection"); services.AddCors(options => { options.AddPolicy(AllowAll, builder => { builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); #region Mapper var mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new MappingProfile()); }); IMapper mapper = mappingConfig.CreateMapper(); services.AddSingleton(mapper); #endregion #region IOC IoCConfig.Config(services, Configuration); #endregion #region Cors services.AddCors(options => { options.AddPolicy("AllowAll", builder => { builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); }); }); services.Configure <MvcOptions>(options => { options.Filters.Add(new CorsAuthorizationFilterFactory("AllowAll")); }); #endregion #region Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Authentication Application", Version = "v1", Description = "Exemplo de api para o projeto de autenticação", Contact = new Contact { Name = "Jonatas Marins" } }); var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); #endregion #region DbContext string connectionString = Configuration.GetConnectionString("DefaultConnection"); services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(connectionString)); #endregion #region Identity //services.AddIdentityCore<ApplicationUser>() // .AddEntityFrameworkStores<ApplicationDbContext>(); // Ativando a utilização do ASP.NET Identity, a fim de // permitir a recuperação de seus objetos via injeção de // dependências services.AddIdentity <ApplicationUser, IdentityRole>(options => { options.Password.RequireDigit = false; options.Password.RequiredLength = 4; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; options.SignIn.RequireConfirmedEmail = false; options.SignIn.RequireConfirmedPhoneNumber = false; }).AddEntityFrameworkStores <ApplicationDbContext>().AddDefaultTokenProviders(); #endregion #region JWT var tokenConfigurations = new TokenConfigurations(); new ConfigureFromConfigurationOptions <TokenConfigurations>( Configuration.GetSection("TokenConfigurations") ).Configure(tokenConfigurations); services.AddSingleton(tokenConfigurations); var symetricKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tokenConfigurations.Key)); services.AddAuthentication(authOptions => { authOptions.DefaultAuthenticateScheme = "Bearer"; authOptions.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(bearerOptions => { var paramsValidation = bearerOptions.TokenValidationParameters; paramsValidation.IssuerSigningKey = symetricKey; paramsValidation.ValidAudience = tokenConfigurations.Audience; paramsValidation.ValidIssuer = tokenConfigurations.Issuer; // Valida a assinatura de um token recebido paramsValidation.ValidateIssuerSigningKey = true; // Verifica se um token recebido ainda é válido paramsValidation.ValidateLifetime = true; // Tempo de tolerância para a expiração de um token (utilizado // caso haja problemas de sincronismo de horário entre diferentes // computadores envolvidos no processo de comunicação) paramsValidation.ClockSkew = TimeSpan.Zero; }); // Ativa o uso do token como forma de autorizar o acesso // a recursos deste projeto services.AddAuthorization(auth => { auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder() .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme) .RequireAuthenticatedUser().Build()); }); #endregion services.AddSingleton(_ => Configuration); }