DRN.Framework.Hosting
0.7.0-preview057
Prefix Reserved
See the version list below for details.
dotnet add package DRN.Framework.Hosting --version 0.7.0-preview057
NuGet\Install-Package DRN.Framework.Hosting -Version 0.7.0-preview057
<PackageReference Include="DRN.Framework.Hosting" Version="0.7.0-preview057" />
<PackageVersion Include="DRN.Framework.Hosting" Version="0.7.0-preview057" />
<PackageReference Include="DRN.Framework.Hosting" />
paket add DRN.Framework.Hosting --version 0.7.0-preview057
#r "nuget: DRN.Framework.Hosting, 0.7.0-preview057"
#:package DRN.Framework.Hosting@0.7.0-preview057
#addin nuget:?package=DRN.Framework.Hosting&version=0.7.0-preview057&prerelease
#tool nuget:?package=DRN.Framework.Hosting&version=0.7.0-preview057&prerelease
DRN.Framework.Hosting
Introduction
DRN.Framework.Hosting package provides practical, effective distributed application hosting code with sensible defaults, configuration options.
This package manages configuration, logging, http server (Kestrel) codes and configuration. Since each distributed app at least requires an endpoint to support health checking, this packages assumes each distributed application is also a web application.
QuickStart: Basics
Here's a basic test demonstration to take your attention and get you started:
using DRN.Framework.Hosting.DrnProgram;
using Sample.Application;
using Sample.Infra;
namespace Sample.Hosted;
public class Program : DrnProgramBase<Program>, IDrnProgram
{
public static async Task Main(string[] args) => await RunAsync(args);
protected override void AddServices(IServiceCollection services) => services
.AddSampleInfraServices()
.AddSampleApplicationServices();
}
You can easily test your application with DRN.Framework.Testing package.
public class StatusControllerTests(ITestOutputHelper outputHelper)
{
[Theory]
[DataInline]
public async Task StatusController_Should_Return_Status(DrnTestContext context)
{
context.ApplicationContext.LogToTestOutput(outputHelper);
var application = context.ApplicationContext.CreateApplication<Program>();
await context.ContainerContext.Postgres.ApplyMigrationsAsync();
var client = application.CreateClient();
var status = await client.GetFromJsonAsync<ConfigurationDebugViewSummary>("Status");
var programName = typeof(Program).GetAssemblyName();
status?.ApplicationName.Should().Be(programName);
}
}
Configuration
DRN hosting package applies configuration in following order:
public static IConfigurationBuilder AddDrnSettings(this IConfigurationBuilder builder, string applicationName, string[]? args = null,
string settingJsonName = "appsettings",
IServiceCollection? sc = null)
{
if (string.IsNullOrWhiteSpace(settingJsonName))
settingJsonName = "appsettings";
var fileProvider = builder.Properties
.Where(pair => pair.Value.GetType() == typeof(PhysicalFileProvider))
.Select(pair => (PhysicalFileProvider)pair.Value).FirstOrDefault();
var environment = GetEnvironment(settingJsonName, args, sc, fileProvider?.Root);
builder.AddJsonFile($"{settingJsonName}.json", true);
builder.AddJsonFile($"{settingJsonName}.{environment.ToString()}.json", true);
if (applicationName.Length > 0)
try
{
var assembly = Assembly.Load(new AssemblyName(applicationName));
builder.AddUserSecrets(assembly, true);
}
catch (FileNotFoundException e)
{
_ = e;
}
builder.AddSettingsOverrides(args, sc);
return builder;
}
private static void AddSettingsOverrides(this IConfigurationBuilder builder, string[]? args, IServiceCollection? sc)
{
builder.AddEnvironmentVariables("ASPNETCORE_");
builder.AddEnvironmentVariables("DOTNET_");
builder.AddEnvironmentVariables();
builder.AddMountDirectorySettings(sc);
if (args != null && args.Length > 0)
builder.AddCommandLine(args);
}
/// <summary>
/// Mounted settings like kubernetes secrets or configmaps
/// </summary>
public static IConfigurationBuilder AddMountDirectorySettings(this IConfigurationBuilder builder, IServiceCollection? sc = null)
{
var overrideService = sc?.BuildServiceProvider().GetService<IMountedSettingsConventionsOverride>();
var mountOverride = overrideService?.MountedSettingsDirectory;
if (overrideService != null)
builder.AddObjectToJsonConfiguration(overrideService);
builder.AddKeyPerFile(MountedSettingsConventions.KeyPerFileSettingsMountDirectory(mountOverride), true);
var jsonDirectory = MountedSettingsConventions.JsonSettingDirectoryInfo(mountOverride);
if (!jsonDirectory.Exists) return builder;
foreach (var files in jsonDirectory.GetFiles())
builder.AddJsonFile(files.FullName);
return builder;
}
You can easily obtain effective configuration with appSettings. Api controller is used for demonstration. Do not expose your configuration.
[ApiController]
[Route("[controller]")]
public class StatusController(IAppSettings appSettings) : ControllerBase
{
[HttpGet]
[ProducesResponseType(200)]
public ActionResult Status()
{
return Ok(appSettings.GetDebugView().ToSummary());
}
}
Logging
DrnProgramBase applies Serilog configurations. Console and Graylog sinks are supported by default. To configure logging you can add serilog configs in appsettings.json
{
"Serilog": {
"Docs": "https://github.com/serilog/serilog-settings-configuration",
"Using": [
"Serilog.Sinks.Console",
"Serilog.Sinks.Graylog"
],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",
"outputTemplate": "[BEGIN {Timestamp:HH:mm:ss.fffffff} {Level:u3} {SourceContext}]{NewLine}{Message:lj}{NewLine}[END {Timestamp:HH:mm:ss.fffffff} {Level:u3} {SourceContext}]{NewLine}"
}
},
{
"Name": "Graylog",
"Args": {
"hostnameOrAddress": "localhost",
"port": "12201",
"transportType": "Udp"
}
}
]
}
}
Kestrel
DrnProgramBase applies Kestrel configurations. To configure logging you should add kestrel configs in appsettings.json
{
"Kestrel": {
"Docs": "https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints",
"EndpointDefaults": {
"Protocols": "Http1"
},
"Endpoints": {
"All": {
"Url": "http://*:5988"
}
}
}
}
DrnProgramBase RunAsync
DrnProgramBase handles most of the application level wiring and standardizes JsonDefaults across all of the System.Text.Json usages.
protected static async Task RunAsync(string[]? args = null)
{
var configuration = new ConfigurationBuilder().AddDrnSettings(GetApplicationAssemblyName(), args).Build();
var appSettings = new AppSettings(configuration);
var scopedLog = new ScopedLog(appSettings).WithLoggerName(typeof(TProgram).FullName);
var loggerProvider = new NLogLoggerProvider(NLogOptions, CreateLogFactory(appSettings));
var logger = loggerProvider.CreateLogger(typeof(TProgram).FullName!);
try
{
scopedLog.AddToActions("Creating Application");
var application = await CreateApplicationAsync(args, appSettings, scopedLog);
scopedLog.AddToActions("Running Application");
logger.LogWarning("{@Logs}", scopedLog.Logs);
if (appSettings.DevelopmentSettings.TemporaryApplication)
return;
//todo create startup report for dev environment
await application.RunAsync();
scopedLog.AddToActions("Application Shutdown Gracefully");
}
catch (Exception exception)
{
scopedLog.AddException(exception);
await TryCreateStartupExceptionReport(args, appSettings, scopedLog, exception, logger);
throw;
}
finally
{
if (scopedLog.HasException)
logger.LogError("{@Logs}", scopedLog.Logs);
else
logger.LogWarning("{@Logs}", scopedLog.Logs);
loggerProvider.Dispose();
}
}
public static async Task<WebApplication> CreateApplicationAsync(string[]? args, IAppSettings appSettings, IScopedLog scopeLog)
{
var actions = GetApplicationAssembly().CreateSubType<DrnProgramActions>();
var (program, applicationBuilder) = await CreateApplicationBuilder(args, appSettings, scopeLog);
await (actions?.ApplicationBuilderCreatedAsync(program, applicationBuilder, appSettings, scopeLog) ?? Task.CompletedTask);
var application = applicationBuilder.Build();
program.ConfigureApplication(application, appSettings);
await (actions?.ApplicationBuiltAsync(program, application, appSettings, scopeLog) ?? Task.CompletedTask);
var requestPipelineSummary = application.GetRequestPipelineSummary();
if (appSettings.IsDevEnvironment) //todo send application summaries to nexus for auditing, implement application dependency summary as well
scopeLog.Add(nameof(RequestPipelineSummary), requestPipelineSummary);
program.ValidateEndpoints(application, appSettings);
await program.ValidateServicesAsync(application, scopeLog);
await (actions?.ApplicationValidatedAsync(program, application, appSettings, scopeLog) ?? Task.CompletedTask);
return application;
}
Local Development Infrastructure
You can leverage DRN.Framework.Testing's container management features directly in your hosted application to automatically provision infrastructure (like Postgres) during local development.
Setup
Add Conditional Reference: Add a reference to
DRN.Framework.Testingthat is only active inDebugconfiguration.<ItemGroup Condition="'$(Configuration)' == 'Debug'"> <ProjectReference Include="..\DRN.Framework.Testing\DRN.Framework.Testing.csproj" /> </ItemGroup>Configure Startup Actions: Implement
DrnProgramActionsto hook into the application startup and launch dependencies.// Sample.Hosted/SampleProgramActions.cs #if DEBUG using DRN.Framework.Hosting.DrnProgram; using DRN.Framework.Testing.Extensions; // ... other usings public class SampleProgramActions : DrnProgramActions { public override async Task ApplicationBuilderCreatedAsync<TProgram>( TProgram program, WebApplicationBuilder builder, IAppSettings appSettings, IScopedLog scopedLog) { await builder.LaunchExternalDependenciesAsync(scopedLog, appSettings); } } #endif
This allows your application to strictly depend on Hosting in production while benefiting from Testing's infrastructure tools during development.
DrnDefaults
DrnProgramBase has a DrnProgramOptions property which defines behavior and defaults to WebApplication and WebApplicationBuilder. See following document for new hosting model introduced with .NET 6,
DrnDefaults are added to empty WebApplicationBuilder and WebApplication and considered as sensible and configurable. Further Overriding and fine-tuning options for DrnDefaults can be added in versions after 0.3.0.
protected DrnProgramSwaggerOptions DrnProgramSwaggerOptions { get; private set; } = new();
// ReSharper disable once StaticMemberInGenericType
protected static NLogAspNetCoreOptions NLogOptions { get; set; } = new()
{
ReplaceLoggerFactory = false,
RemoveLoggerFactoryFilter = false
};
protected DrnAppBuilderType AppBuilderType { get; set; } = DrnAppBuilderType.DrnDefaults;
protected abstract Task AddServicesAsync(WebApplicationBuilder builder, IAppSettings appSettings, IScopedLog scopedLog);
protected virtual void ConfigureApplicationBuilder(WebApplicationBuilder applicationBuilder, IAppSettings appSettings)
{
applicationBuilder.Logging.ClearProviders();
if (appSettings.TryGetSection("Logging", out var loggingSection))
applicationBuilder.Logging.AddConfiguration(loggingSection);
applicationBuilder.Logging.AddNLogWeb(CreateLogFactory(appSettings), NLogOptions);
applicationBuilder.WebHost.UseKestrelCore().ConfigureKestrel(kestrelServerOptions =>
{
kestrelServerOptions.AddServerHeader = false;
kestrelServerOptions.Configure(applicationBuilder.Configuration.GetSection("Kestrel"));
});
applicationBuilder.WebHost.UseStaticWebAssets();
var services = applicationBuilder.Services;
services.AddDrnHosting(DrnProgramSwaggerOptions, appSettings.Configuration);
// ... (Endpoints & Mvc configuration)
services.AddAuthorization(ConfigureAuthorizationOptions);
if (AppBuilderType != DrnAppBuilderType.DrnDefaults) return;
// ... (Defaults configuration)
}
protected virtual void ConfigureApplication(WebApplication application, IAppSettings appSettings)
{
if (AppBuilderType != DrnAppBuilderType.DrnDefaults) return;
ConfigureApplicationPipelineStart(application, appSettings);
ConfigureApplicationPreScopeStart(application, appSettings);
application.UseMiddleware<HttpScopeMiddleware>();
ConfigureApplicationPostScopeStart(application, appSettings);
application.UseRouting();
ConfigureApplicationPreAuthentication(application, appSettings);
application.UseAuthentication();
application.UseMiddleware<ScopedUserMiddleware>();
ConfigureApplicationPostAuthentication(application, appSettings);
application.UseAuthorization();
application.UseResponseCaching();
ConfigureApplicationPostAuthorization(application, appSettings);
MapApplicationEndpoints(application, appSettings);
}
Semper Progressivus: Always Progressive
Commit Info
Author: Duran Serkan KILIÇ
Date: 2026-01-25 10:27:24 +0300
Hash: 7703f177a808c9188630ababed58c565601f380b
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- DRN.Framework.Utils (>= 0.7.0-preview057)
- Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation (>= 10.0.2)
- NetEscapades.AspNetCore.SecurityHeaders (>= 1.3.1)
- NLog.Targets.Network (>= 6.0.3)
- NLog.Web.AspNetCore (>= 6.1.0)
- Swashbuckle.AspNetCore (>= 10.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DRN.Framework.Hosting:
| Package | Downloads |
|---|---|
|
DRN.Framework.Testing
DRN.Framework.Testing package encapsulates testing dependencies and provides practical, effective helpers such as resourceful data attributes and test context. This package enables a new encouraging testing technique called as DTT(Duran's Testing Technique). With DTT, any developer can write clean and hassle-free unit and integration tests without complexity. ## Commit Info Author: Duran Serkan KILIÇ Date: 2026-03-26 21:45:03 +0300 Hash: 30e1be57f4eb7a89ca3ee1b45ce745fee9428273 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.9.1 | 101 | 3/26/2026 |
| 0.9.0 | 89 | 3/25/2026 |
| 0.9.0-preview001 | 94 | 3/22/2026 |
| 0.8.0 | 106 | 3/14/2026 |
| 0.7.0 | 95 | 3/8/2026 |
| 0.7.0-preview067 | 93 | 3/7/2026 |
| 0.7.0-preview066 | 102 | 2/28/2026 |
| 0.7.0-preview065 | 98 | 2/25/2026 |
| 0.7.0-preview064 | 99 | 2/22/2026 |
| 0.7.0-preview063 | 99 | 2/21/2026 |
| 0.7.0-preview062 | 98 | 2/11/2026 |
| 0.7.0-preview061 | 126 | 2/7/2026 |
| 0.7.0-preview060 | 104 | 1/28/2026 |
| 0.7.0-preview059 | 119 | 1/26/2026 |
| 0.7.0-preview058 | 114 | 1/25/2026 |
| 0.7.0-preview057 | 107 | 1/25/2026 |
| 0.7.0-preview056 | 111 | 1/10/2026 |
| 0.7.0-preview055 | 286 | 12/16/2025 |
| 0.7.0-preview054 | 201 | 12/13/2025 |
| 0.7.0-preview053 | 143 | 12/12/2025 |
Not every version includes changes, features or bug fixes. This project can increment version to keep consistency with other DRN.Framework projects.
## Version 0.7.0
My family celebrates the enduring legacy of Mustafa Kemal Atatürk's enlightenment ideals.
### New Features
* IdentityControllerBase classes added which are controller version of Identity Api endpoints.
* DrnProgramBase
* ConfigureSecurityHeaders virtual method added.
* ConfigureApplicationPreScopeStart will add security headers configured by ConfigureSecurityHeaders
## Version 0.6.0
My family celebrates the enduring legacy of Mustafa Kemal Atatürk's enlightenment ideals. This release is dedicated to the memory of Mustafa Kemal Atatürk, founder of the Republic of Türkiye, and to his vision for a modern, enlightened, democratic nation. In his eternal rest, he continues to guide us through his ideals of freedom, progress, and national sovereignty.
### New Features
* DrnProgramBase
* MvcBuilder configuration separated into virtual method
* RazorRuntimeCompilation support added
* Exception is no longer swallowed by DrnProgramBase to fail integration tests gracefully
* Multifactor Authentication
* Mfa detail added to scopedlog with ScopedUserMiddleware
* Mfa and Mfa exempt policies added with AuthPolicy helper class
* DrnProgramBase.ConfigureAuthorizationOptions enforces Mfa by default
* MfaExempt policy can be used with Authorize attribute to bypass mfa
* ConfigureMFARedirection and ConfigureMFAExemption virtual methods added to DrnProgramBase
* PageCollectionBase and EndpointCollectionBase classes added to manage page and endpoint references
### Breaking Changes
* DrnProgramBase refactored
* Static properties removed to improve application stability during integration tests
* New overridable virtual methods added to improve configurability
* Overridable virtual method parameters changed to accept instance parameters since static properties does not exist anymore.
## Version 0.5.0
My family celebrates the enduring legacy of Mustafa Kemal Atatürk's enlightenment ideals. This release is dedicated to August 30 Victory Day, a day that marks the decisive victory achieved by the Turkish people against imperialism during the Turkish War of Independence, leading to the establishment of the Republic of Türkiye.
### New Features
* ScopedUserMiddleware
* sets IScopedUser with current user belongs to the request scope
* updates IScopedLog with UserId and UserAuthenticated info
* HttpScopeHandler
* Initializes ScopeContext with TraceId, IScopedLog and IScopedUser
* DrnException handling as default application exception handling
* DrnExceptions can be used to short circuit the processing pipeline
* FlurlHttpException handling as default gateway exception handling
* In Development environment - HttpResponse returns ScopedLog as developer exception result
* l5d-client-id is added to scoped log by default
* HttpRequestLogger
* Request and response logs improvements
* DrnProgramBase
* HostOptions become configurable with Configuration.GetSection("HostOptions")
* overrideable ConfigureSwaggerOptions
* Added swagger support by default in development environment
### Breaking Changes
* DrnProgramBase
* DrnProgramOptions - Removed
## Version 0.4.0
My family celebrates the enduring legacy of Mustafa Kemal Atatürk's enlightenment ideals. This release is dedicated to 19 May Commemoration of Atatürk, Youth and Sports Day.
### Breaking Changes
* HttpScopeLogger is renamed as HttpScopeHandler
### New Features
* EndpointsApiExplorer - added to service collection by DrnProgramBase to support OpenAPI Specification
* NexusClient - added for initial service discovery and remote configuration management development
* DrnProgramBase has new overridable configuration methods
* ConfigureApplicationPreScopeStart
* ConfigureApplicationPostScopeStart
* MapApplicationEndpoints
## Version 0.3.0
My family celebrates the enduring legacy of Mustafa Kemal Atatürk's enlightenment ideals. This release is dedicated to 23 April National Sovereignty and Children's Day.
### New Features
* DrnProgramBase and IDrnProgram - added to minimize development efforts with sensible defaults
* HttpScopeLogger and HttpRequestLogger middlewares - added to support structured logging
---
**Semper Progressivus: Always Progressive**
## Commit Info
Author: Duran Serkan KILIÇ
Date: 2026-01-25 10:27:24 +0300
Hash: 7703f177a808c9188630ababed58c565601f380b