Auto.Caching.Redis
1.0.0
dotnet add package Auto.Caching.Redis --version 1.0.0
NuGet\Install-Package Auto.Caching.Redis -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Auto.Caching.Redis" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Auto.Caching.Redis --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Auto.Caching.Redis, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Auto.Caching.Redis as a Cake Addin #addin nuget:?package=Auto.Caching.Redis&version=1.0.0 // Install Auto.Caching.Redis as a Cake Tool #tool nuget:?package=Auto.Caching.Redis&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Auto Core (基于AspectCore)
介绍
AutoCore是基于 .Net Standard 2.1用于简化 ASP.NET Core开发,AutoCore 在 AspectCore 的基础上进行功能开发,AspectCore 在性能上都比反射有2个数量级的优化,达到了和硬编码调用相同的数量级。
AspectCore 方法调用反射扩展
性能测试:(Reflection为.NET Core提供的反射调用,Reflector为AspectCore.Extension.Reflection调用,Native为硬编码调用
| Method | Mean | Error | StdDev | StdErr | Op/s |
|------------------- |------------:|----------:|----------:|----------:|----------------:|
| Native_Call | 1.0473 ns | 0.0064 ns | 0.0050 ns | 0.0015 ns | 954,874,046.8 |
| Reflection_Call | 91.9543 ns | 0.3540 ns | 0.3311 ns | 0.0855 ns | 10,874,961.4 |
| Reflector_Call | 7.1544 ns | 0.0628 ns | 0.0587 ns | 0.0152 ns | 139,774,408.3 |
快速开始
- 安装
Install-Package Auto.Core
dotnet add package Auto.Core
- 配置 ServiceProviderFactory
builder.Host.UseServiceProviderFactory(new AutoServiceProviderFactory());
- 注册AutoCore
builder.Services.AddAutoCore(builder.Configuration);
- AutoOptions (选项)
//appsettings.json
{
"Redis": {
"Host": "localhost",
"Port": 6379,
"Password": "zxc123..."
}
}
//选项类:标记绑定
[AutoOptions(Node ="Redis")]
public class Redis
{
public string Host { get; set; }
public int Port { get; set; }
public string Password { get; set; }
}
//构造函数注入
private readonly Redis _redis;
public WeatherForecast(IOptionsSnapshot<Redis> options)
{
_redis = options.Value;
}
- AutoCache (缓存)
//方法:标记缓存
[AutoCache]
public virtual async Task<IEnumerable<WeatherForecast>> Get(User user)
{
var ss = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray();
return ss;
}
- AutoService(服务注册)
//接口
public interface IUser
{
void Get();
}
//实现:标记注册
[AutoService]
public class User : IUser
{
public void Get()
{
Console.WriteLine(1);
}
}
//构造函数注入
private readonly IUser _user;
public WeatherForecastController(IUser user)
{
_user = user;
}
- 参数校验
//参数校验:参数标记校验方法
public WeatherForecast([NotNull] string userName)
{
string un = userName;
}
AutoCache(缓存)
- redis缓存提供
Install-Package Auto.Core.Redis
{
"RedisOptions": {
"Host": "127.0.0.1",
"Port": 6379,
"Database": 0
}
}
AutoValidation(参数校验)
字符串最大长度 [MaxLengthAttribute]
字符串最小长度 [MinLengthAttribute]
字符串不能为空或Null [NotNullOrEmptyAttribute]
字符串不能为Null或空格 [NotNullOrWhiteSpaceAttribute]
对象不能为Null [NotNullAttribute]
范围 [RangeAttribute]
常见问题
功能无法正常使用
- 检查方法设置为 virtual
[HttpPost(Name = "GetWeatherForecast")]
[AutoCache]
public virtual async Task<IEnumerable<WeatherForecast>> Get(User user)
{
var ss = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray();
return ss;
}
}
注意:控制器中的方法需要注册为服务后才可以使用
builder.Services.AddControllers().AddControllersAsServices();
- 检查是否注册AutoCore
builder.Services.AddAutoCore(builder.Configuration);
- 检查是否配置ServiceProviderFactory
builder.Host.UseServiceProviderFactory(new AutoServiceProviderFactory());
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- Auto.Core (>= 1.0.0)
- FreeRedis (>= 1.1.2)
- Microsoft.Extensions.Configuration (>= 7.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 217 | 7/13/2023 |
支持redis缓存