initial commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Common.Core.Extensions;
|
||||
|
||||
public static class ConfigurationExtension
|
||||
{
|
||||
public static IConfigurationBuilder Initialize(this IConfigurationBuilder builder)
|
||||
{
|
||||
string env = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Production";
|
||||
|
||||
return builder
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{env}.json", optional: true, reloadOnChange: true)
|
||||
.AddEnvironmentVariables();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace Common.Core.Extensions;
|
||||
|
||||
public static class ServicesExtension
|
||||
{
|
||||
public static TModel? TryGetService<TModel>(this IServiceProvider serviceProvider) where TModel : class
|
||||
{
|
||||
try
|
||||
{
|
||||
return (TModel?)serviceProvider.GetService(typeof(TModel));
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
// ignore as we do not care...
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user