UgenTec.Defaults QuickStart
The UgenTec.Defaults
Block contains Ugentec opinionated logic unrelated to the type of application or hosting chosen.
Installation
Use the internal Ugentec Nuget-2 feed to install the UgenTec.Defaults library
install-package UgenTec.Defaults
HttpClient
UgenTec.Defaults currently only contains a helper for configuring HttpClients to translate http responses with specific status codes back into exceptions. It extends the Ugentec.Framework.Core.Http library.
Example
serviceCollection.AddHttpClient<IProxy,Proxy>()
.WithHttpStatusCodeToExceptionMapping(
cfg=>cfg.MapDefaultUgenTecStatusCodesToExceptions())
DbContext configuration
UgenTec.Defaults contains a convenience method for configuring DbContexts according to UgenTec standards, making the migration strategy to be used explicit.
Example
services.AddUgenTecDefaultDbContext<SampleDbContext>(configure =>
{
//Establish the Schema and Migration history table names
configure.WithMigrationHistoryTableName(SampleDbContext.MigrationHistoryTableName)
.WithSchemaName(SampleDbContext.SchemaName);
//Establish the migration strategy
if(configuration.GetValue<bool>("PLATFORMCONFIGURATION:ALLOWAUTOMATICDATABASEMIGRATIONS"))
{
configure.WithAutomaticMigrations();
}
else
{
configure.WithExplicitMigrations(cfg => cfg.WithContextFactoryMethodForMigration((options, migrationStrategy, loggerFactory) => new SampleDbContext(options, migrationStrategy, loggerFactory)));
}
//Enable sensitive data logging when running in development context
if (hostingEnvironment.IsDevelopment())
{
configure.EnableSensitiveDataLogging();
}
});