The following articles explain the issue using HttpClient class:
https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
http://www.nimaara.com/2016/11/01/beware-of-the-net-httpclient/
As per ASP.NET 2.1 road map a default HttpClient Service will be available. Until the framework available, I'm using the below implementation of HttpClient
https://gist.github.com/ajopjo/796ddf8d2f44dd3dbf6268da179cb239
If you find any issues with the implementation, please let me know.
I’m not a nerd!! But I love to learn technology. Have a good collection of tech book soft copies, hardly read. Always bing to solve problem. Now decided to scribble - whatever I binged for my tech work!!!! Disclaimer: This is not my view ;) itz collated views
Monday, February 26, 2018
Thursday, February 22, 2018
Integrating Serilog to ASP.NET Core
If you are not using the seri log configuration package and want to set up serilog based on app specific configuration use
webHostBuilder.ConfigureLogging((hostingcontext, logging) =>
{
var logSettings = new LogConfiguration();
//my custom section
hostingcontext.Configuration.GetSection("LogSettings").Bind(logSettings);
if (logSettings.Sink.Equals("rollingFile"))
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", Information)
.Enrich.FromLogContext()
.WriteTo.RollingFile(logSettings.Url)
.CreateLogger();
}
else
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", Information)
.Enrich.FromLogContext()
.WriteTo.Seq(logSettings.Url)
.CreateLogger();
}
var levelSwitch = new LoggingLevelSwitch();
int.TryParse(logSettings.LogLevel, out var level);
levelSwitch.MinimumLevel = (LogEventLevel)level;
logging.AddSerilog(dispose: true);
});
webHostBuilder.ConfigureLogging((hostingcontext, logging) =>
{
var logSettings = new LogConfiguration();
//my custom section
hostingcontext.Configuration.GetSection("LogSettings").Bind(logSettings);
if (logSettings.Sink.Equals("rollingFile"))
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", Information)
.Enrich.FromLogContext()
.WriteTo.RollingFile(logSettings.Url)
.CreateLogger();
}
else
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", Information)
.Enrich.FromLogContext()
.WriteTo.Seq(logSettings.Url)
.CreateLogger();
}
var levelSwitch = new LoggingLevelSwitch();
int.TryParse(logSettings.LogLevel, out var level);
levelSwitch.MinimumLevel = (LogEventLevel)level;
logging.AddSerilog(dispose: true);
});
Autofac dependency injection per request based on header parameter ASP.NET Core2.0
builder.Register(c =>
{
string dependencyName= c.Resolve<IHttpContextAccessor>().HttpContext.Request.Headers[Constants.CountryHeader];
return c.ResolveNamed<interface>(dependencyName);
}).InstancePerLifetimeScope();
and in the module
protected override void Load(ContainerBuilder builder)
{
//register modules here
builder.RegisterType<ClassName>().Named<Interfacer>("Name of dependency");
}
{
string dependencyName= c.Resolve<IHttpContextAccessor>().HttpContext.Request.Headers[Constants.CountryHeader];
return c.ResolveNamed<interface>(dependencyName);
}).InstancePerLifetimeScope();
and in the module
protected override void Load(ContainerBuilder builder)
{
//register modules here
builder.RegisterType<ClassName>().Named<Interfacer>("Name of dependency");
}
Subscribe to:
Posts (Atom)
Featured post
How to connect to Mongo Atlas from Robo 3T
If you use a local instance of MongoDB, you might be a great fan of Robo3T. However, if you are using Mongo Atlas, the Atlas web interface p...
Popular Posts
-
Last week I was working on on-boarding a few SAP Odata APIs to API Management gateway. The APIM tool used by my organization supports JSON ...
-
Our team has used EWS API's Appointment service to book a meeting room. During our testing, its been noted that the room was not block...
-
When comes to API maturity model there are two major models: 1. Richardson Maturity Model 2. Amundsen Maturity Model. To attain RMM...