Rougamo.Extensions.DependencyInjection.GenericHost
8.0.0
See the version list below for details.
dotnet add package Rougamo.Extensions.DependencyInjection.GenericHost --version 8.0.0
NuGet\Install-Package Rougamo.Extensions.DependencyInjection.GenericHost -Version 8.0.0
<PackageReference Include="Rougamo.Extensions.DependencyInjection.GenericHost" Version="8.0.0" />
paket add Rougamo.Extensions.DependencyInjection.GenericHost --version 8.0.0
#r "nuget: Rougamo.Extensions.DependencyInjection.GenericHost, 8.0.0"
// Install Rougamo.Extensions.DependencyInjection.GenericHost as a Cake Addin #addin nuget:?package=Rougamo.Extensions.DependencyInjection.GenericHost&version=8.0.0 // Install Rougamo.Extensions.DependencyInjection.GenericHost as a Cake Tool #tool nuget:?package=Rougamo.Extensions.DependencyInjection.GenericHost&version=8.0.0
Rougamo.DI
中文 | English
Rougamo.DI
provides a set of IoC/DI extensions for Rougamo that enhance the IoC/DI interaction experience when using Rougamo.
Available Extensions
Package Name | Description |
---|---|
Rougamo.Extensions.DependencyInjection.AspNetCore | Uses the official DependencyInjection and integrates with HttpContext to return the correct scoped IServiceProvider |
Rougamo.Extensions.DependencyInjection.GenericHost | Uses the official DependencyInjection , suitable for non-AspNetCore Generic Host projects |
Rougamo.Extensions.DependencyInjection.Autofac.AspNetCore | Uses Autofac and integrates with HttpContext to return the correct scoped ILifetimeScope |
Rougamo.Extensions.DependencyInjection.Autofac | Uses Autofac , suitable for non-AspNetCore projects |
Rougamo.Extensions.DependencyInjection.Abstractions | The base abstraction package for all other packages |
Rougamo.Extensions.DependencyInjection.AspNetCore.Abstractions | The base abstraction package for all AspNetCore-related packages |
Versioning Guidelines
All version numbers follow the Semantic Versioning (SemVer) format
- The version numbers of the two foundational abstraction packages start from
1.0.0
and increase incrementally:Rougamo.Extensions.DependencyInjection.Abstractions
Rougamo.Extensions.DependencyInjection.AspNetCore.Abstractions
- For Microsoft official DI extension packages, the major version matches the corresponding official package (e.g.,
Microsoft.Extensions.*
):Rougamo.Extensions.DependencyInjection.AspNetCore
Rougamo.Extensions.DependencyInjection.GenericHost
- For Autofac extension packages, the major version matches the corresponding official
Autofac
package:Rougamo.Extensions.DependencyInjection.Autofac.AspNetCore
Rougamo.Extensions.DependencyInjection.Autofac
Rougamo.Extensions.DependencyInjection.AspNetCore
Quick Start
// Register Rougamo (Note: Rougamo does not require registration if you do not need IoC/DI features)
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// ... other setup steps
builder.Services.AddRougamoAspNetCore();
// ... other setup steps
}
// Accessing IServiceProvider in an aspect
public class TestAttribute : MoAttribute
{
public override void OnEntry(MethodContext context)
{
// Use the extension method GetServiceProvider to obtain the IServiceProvider instance
var services = context.GetServiceProvider();
// Utilize IServiceProvider
var xxx = services.GetService<IXxx>();
}
}
Non-HttpContext Scope
By default, the extension method GetServiceProvider
on MethodContext
only attempts to retrieve the IServiceProvider
for the current HttpContext
scope. If there is no HttpContext
, it will return the root IServiceProvider
. This design assumes that in AspNetCore projects, scopes are typically not manually created. If you have a scenario where you need to manually create a scope, follow the steps below:
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// ... other setup steps
builder.Services.AddNestableHttpContextScopeAccessor(); // Additional registration step
builder.Services.AddRougamoAspNetCore();
// ... other setup steps
}
public class Cls(IServiceProvider services)
{
public void M()
{
// Use the extension method CreateResolvableScope to create a scope.
// If you use CreateScope, that scope will not be accessible in aspect types.
using var scope = services.CreateResolvableScope();
}
}
Rougamo.Extensions.DependencyInjection.GenericHost
// Register Rougamo (Note: Rougamo does not require registration if you do not need IoC/DI features)
public static void Main(string[] args)
{
var builder = Host.CreateDefaultBuilder();
// ... other setup steps
builder.ConfigureServices(services => services.AddRougamoGenericHost());
// ... other setup steps
}
// Accessing IServiceProvider in an aspect
public class TestAttribute : MoAttribute
{
public override void OnEntry(MethodContext context)
{
// Use the extension method GetServiceProvider to obtain the IServiceProvider instance
var services = context.GetServiceProvider();
// Utilize IServiceProvider
var xxx = services.GetService<IXxx>();
}
}
Rougamo.Extensions.DependencyInjection.Autofac.AspNetCore
Quick Start
// Register Rougamo (Note: Rougamo does not require registration if you do not need IoC/DI features)
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Host
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureContainer<ContainerBuilder>(builder =>
{
builder.RegisterRougamoAspNetCore();
});
// Registering IHttpContextAccessor is also required
builder.Services.AddHttpContextAccessor();
}
// Accessing ILifetimeScope in an aspect
public class TestAttribute : MoAttribute
{
public override void OnEntry(MethodContext context)
{
// Use the extension method GetAutofacCurrentScope to obtain the ILifetimeScope instance
var scope = context.GetAutofacCurrentScope();
// Utilize ILifetimeScope
var xxx = scope.Resolve<IXxx>();
}
}
Non-HttpContext Scope
By default, the GetAutofacCurrentScope
extension method on MethodContext
only attempts to retrieve the ILifetimeScope
for the current HttpContext
. If there is no HttpContext
, it will return the root IServiceProvider
. This design assumes that in AspNetCore projects, scopes are typically not manually created. If you have a scenario where you need to manually create a scope, follow the steps below:
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Host
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureContainer<ContainerBuilder>(builder =>
{
builder.RegisterAutofacNestableHttpContextScopeAccessor(); // Additional registration step
builder.RegisterRougamoAspNetCore();
});
// Registering IHttpContextAccessor is also required
builder.Services.AddHttpContextAccessor();
}
public class Cls(IServiceProvider services)
{
public void M()
{
// Use the extension method BeginResolvableLifetimeScope to create a scope.
// If you use BeginLifetimeScope, that scope will not be accessible in aspect types.
using var scope = services.BeginResolvableLifetimeScope();
}
}
Rougamo.Extensions.DependencyInjection.Autofac
// Register Rougamo (Note: Rougamo does not require registration if you do not need IoC/DI features)
public static void Main(string[] args)
{
var builder = Host.CreateDefaultBuilder();
builder
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
.ConfigureContainer<ContainerBuilder>(builder =>
{
builder.RegisterRougamo();
});
}
// Accessing ILifetimeScope in an aspect
public class TestAttribute : MoAttribute
{
public override void OnEntry(MethodContext context)
{
// Use the extension method GetAutofacCurrentScope to obtain the ILifetimeScope instance
var scope = context.GetAutofacCurrentScope();
// Utilize ILifetimeScope
var xxx = scope.Resolve<IXxx>();
}
}
Usage in Framework Projects
If your project is an older WebForm, WinForm, WPF, or similar project that does not use the Microsoft.Extensions.*
packages, you can directly call the RegisterRougamo
extension method when initializing the ContainerBuilder
.
var builder = new ContainerBuilder();
builder.RegisterRougamo();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Rougamo.Extensions.DependencyInjection.Abstractions (>= 1.0.0)
- Rougamo.Fody (>= 1.0.1)
-
net6.0
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Rougamo.Extensions.DependencyInjection.Abstractions (>= 1.0.0)
- Rougamo.Fody (>= 1.0.1)
-
net7.0
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Rougamo.Extensions.DependencyInjection.Abstractions (>= 1.0.0)
- Rougamo.Fody (>= 1.0.1)
-
net8.0
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Rougamo.Extensions.DependencyInjection.Abstractions (>= 1.0.0)
- Rougamo.Fody (>= 1.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Rougamo.Extensions.DependencyInjection.GenericHost:
Package | Downloads |
---|---|
Rougamo.Extensions.DependencyInjection.AspNetCore
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
8.0.1-preview-1726208425 | 126 | 9/13/2024 | |
8.0.0 | 340 | 8/21/2024 | |
7.0.1-preview-1726207796 | 117 | 9/13/2024 | |
7.0.0 | 188 | 8/21/2024 | |
6.0.1-preview-1726206834 | 112 | 9/13/2024 | |
6.0.0 | 186 | 8/21/2024 | |
4.0.0 | 168 | 8/18/2024 | |
4.0.0-priview-1723973798 | 153 | 8/18/2024 | |
3.0.1-preview-1726205321 | 115 | 9/13/2024 | |
3.0.0 | 181 | 8/21/2024 | |
3.0.0-preview-1724277574 | 150 | 8/21/2024 | |
3.0.0-preview-1724277179 | 150 | 8/21/2024 |
# Rougamo.DI
## 版本号说明
**所有版本号格式都采用语义版本号(SemVer)**
1. 两个基础抽象包的版本从`1.0.0`开始增加
- `Rougamo.Extensions.DependencyInjection.Abstractions`
- `Rougamo.Extensions.DependencyInjection.AspNetCore.Abstractions`
2. 微软官方DI扩展包,主版本号与官方包(`Microsoft.Extensions.*`)相同
- `Rougamo.Extensions.DependencyInjection.AspNetCore`
- `Rougamo.Extensions.DependencyInjection.GenericHost`
3. Autofac扩展包,主版本号与官方包(`Autofac`)相同
- `Rougamo.Extensions.DependencyInjection.Autofac.AspNetCore`
- `Rougamo.Extensions.DependencyInjection.Autofac`
更新信息,请查看 [README](https://github.com/inversionhourglass/Rougamo.DI/blob/master/README.md)
---
### Versioning Guidelines
**All version numbers follow the Semantic Versioning (SemVer) format**
1. The version numbers of the two foundational abstraction packages start from `1.0.0` and increase incrementally:
- `Rougamo.Extensions.DependencyInjection.Abstractions`
- `Rougamo.Extensions.DependencyInjection.AspNetCore.Abstractions`
2. For Microsoft official DI extension packages, the major version matches the corresponding official package (e.g., `Microsoft.Extensions.*`):
- `Rougamo.Extensions.DependencyInjection.AspNetCore`
- `Rougamo.Extensions.DependencyInjection.GenericHost`
3. For Autofac extension packages, the major version matches the corresponding official `Autofac` package:
- `Rougamo.Extensions.DependencyInjection.Autofac.AspNetCore`
- `Rougamo.Extensions.DependencyInjection.Autofac`
For more information, visit [Readme on github](https://github.com/inversionhourglass/Rougamo.DI/blob/master/README_en_.md).