Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Qu authored and Victor Qu committed Nov 3, 2022
2 parents 3609f0a + 5da6141 commit d126713
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.201
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nuget-prereleased.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.201
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nuget-released.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.201
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
20 changes: 10 additions & 10 deletions Norns.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
# Visual Studio Version 17
VisualStudioVersion = 17.1.32210.238
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3FD69CA3-BAF7-4B7A-AAB2-B9853759F4D7}"
EndProject
Expand All @@ -19,8 +19,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Norns.Urd.Test", "test\Norn
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Examples.WebApi", "test\Examples.WebApi\Examples.WebApi.csproj", "{DA8A1EF3-7E2B-4EE6-AE2C-57902F5A3E94}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleBenchmark", "test\SimpleBenchmark\SimpleBenchmark.csproj", "{E432067A-D04B-4021-A6A2-4E62EE83139A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Norns.Urd.Extensions.Polly", "src\Norns.Urd.Extensions.Polly\Norns.Urd.Extensions.Polly.csproj", "{F55592A9-DBCC-4B9A-BA25-205CEC8A641A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Norns.Urd.Caching.Memory", "src\Norns.Urd.Caching.Memory\Norns.Urd.Caching.Memory.csproj", "{60AE7517-C5EF-479E-87B7-2BDF2AF45A61}"
Expand All @@ -35,7 +33,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Norns.Urd.HttpClient", "src
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HttpClients", "HttpClients", "{6564067F-6756-4C2A-8E96-5CC3D4E40147}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Norns.Urd.HttpClient.NewtonsoftJson", "src\Norns.Urd.HttpClient.NewtonsoftJson\Norns.Urd.HttpClient.NewtonsoftJson.csproj", "{4DD4DA90-0129-4D05-903A-A454AEE9BED5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Norns.Urd.HttpClient.NewtonsoftJson", "src\Norns.Urd.HttpClient.NewtonsoftJson\Norns.Urd.HttpClient.NewtonsoftJson.csproj", "{4DD4DA90-0129-4D05-903A-A454AEE9BED5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleBenchmark", "test\SimpleBenchmark\SimpleBenchmark.csproj", "{8A40349E-042C-4D4C-8821-DA77D56EE46E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -55,10 +55,6 @@ Global
{DA8A1EF3-7E2B-4EE6-AE2C-57902F5A3E94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA8A1EF3-7E2B-4EE6-AE2C-57902F5A3E94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA8A1EF3-7E2B-4EE6-AE2C-57902F5A3E94}.Release|Any CPU.Build.0 = Release|Any CPU
{E432067A-D04B-4021-A6A2-4E62EE83139A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E432067A-D04B-4021-A6A2-4E62EE83139A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E432067A-D04B-4021-A6A2-4E62EE83139A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E432067A-D04B-4021-A6A2-4E62EE83139A}.Release|Any CPU.Build.0 = Release|Any CPU
{F55592A9-DBCC-4B9A-BA25-205CEC8A641A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F55592A9-DBCC-4B9A-BA25-205CEC8A641A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F55592A9-DBCC-4B9A-BA25-205CEC8A641A}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -83,6 +79,10 @@ Global
{4DD4DA90-0129-4D05-903A-A454AEE9BED5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4DD4DA90-0129-4D05-903A-A454AEE9BED5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4DD4DA90-0129-4D05-903A-A454AEE9BED5}.Release|Any CPU.Build.0 = Release|Any CPU
{8A40349E-042C-4D4C-8821-DA77D56EE46E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A40349E-042C-4D4C-8821-DA77D56EE46E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A40349E-042C-4D4C-8821-DA77D56EE46E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A40349E-042C-4D4C-8821-DA77D56EE46E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -91,7 +91,6 @@ Global
{396F28A0-999B-4CF1-B7EC-74E5F5063BAA} = {3FD69CA3-BAF7-4B7A-AAB2-B9853759F4D7}
{C54ACC90-5597-4C49-96E8-64D15714A1CD} = {115CAC93-F1BB-40FA-A55E-D846ED028024}
{DA8A1EF3-7E2B-4EE6-AE2C-57902F5A3E94} = {115CAC93-F1BB-40FA-A55E-D846ED028024}
{E432067A-D04B-4021-A6A2-4E62EE83139A} = {115CAC93-F1BB-40FA-A55E-D846ED028024}
{F55592A9-DBCC-4B9A-BA25-205CEC8A641A} = {3FD69CA3-BAF7-4B7A-AAB2-B9853759F4D7}
{60AE7517-C5EF-479E-87B7-2BDF2AF45A61} = {1AF242BB-9AA3-469F-83E4-3C1752C9087A}
{1AF242BB-9AA3-469F-83E4-3C1752C9087A} = {3FD69CA3-BAF7-4B7A-AAB2-B9853759F4D7}
Expand All @@ -100,6 +99,7 @@ Global
{D2BF85FF-3D14-40A9-8CE8-A0404FBA1C36} = {6564067F-6756-4C2A-8E96-5CC3D4E40147}
{6564067F-6756-4C2A-8E96-5CC3D4E40147} = {3FD69CA3-BAF7-4B7A-AAB2-B9853759F4D7}
{4DD4DA90-0129-4D05-903A-A454AEE9BED5} = {6564067F-6756-4C2A-8E96-5CC3D4E40147}
{8A40349E-042C-4D4C-8821-DA77D56EE46E} = {115CAC93-F1BB-40FA-A55E-D846ED028024}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C2BFA03B-F071-472F-95AD-C2E127881EDE}
Expand Down
2 changes: 1 addition & 1 deletion ProjectCommon.targets
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\images\icon.png">
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ Intel Core i7-10700 CPU 2.90GHz, 1 CPU, 16 logical and 8 physical cores

| Method | Mean | Error | StdDev | Gen0 | Allocated |
|----------------------------------------------- |----------:|---------:|---------:|-------:|----------:|
| TransientInstanceCallSyncMethodWhenNoAop | 49.63 ns | 0.249 ns | 0.233 ns | 0.0134 | 112 B |
| TransientInstanceCallSyncMethodWhenNornsUrd | 116.59 ns | 0.436 ns | 0.364 ns | 0.0411 | 344 B |
| TransientInstanceCallSyncMethodWhenCastle | 174.01 ns | 0.708 ns | 0.628 ns | 0.0610 | 512 B |
| TransientInstanceCallSyncMethodWhenAspectCore | 434.65 ns | 2.315 ns | 2.052 ns | 0.0772 | 648 B |
| TransientInstanceCallAsyncMethodWhenNoAop | 88.87 ns | 0.909 ns | 0.759 ns | 0.0305 | 256 B |
| TransientInstanceCallAsyncMethodWhenNornsUrd | 222.94 ns | 2.224 ns | 2.080 ns | 0.0668 | 560 B |
| TransientInstanceCallAsyncMethodWhenCastle | 193.51 ns | 1.803 ns | 1.408 ns | 0.0782 | 656 B |
| TransientInstanceCallAsyncMethodWhenAspectCore | 518.50 ns | 2.043 ns | 1.911 ns | 0.1030 | 864 B |
| TransientInstanceCallSyncMethodWhenNoAop | 52.41 ns | 0.319 ns | 0.298 ns | 0.0134 | 112 B |
| TransientInstanceCallSyncMethodWhenNornsUrd | 120.26 ns | 0.237 ns | 0.185 ns | 0.0410 | 344 B |
| TransientInstanceCallSyncMethodWhenCastle | 168.58 ns | 0.842 ns | 0.788 ns | 0.0610 | 512 B |
| TransientInstanceCallSyncMethodWhenAspectCore | 439.43 ns | 1.466 ns | 1.225 ns | 0.0772 | 648 B |
| TransientInstanceCallAsyncMethodWhenNoAop | 88.63 ns | 0.318 ns | 0.282 ns | 0.0305 | 256 B |
| TransientInstanceCallAsyncMethodWhenNornsUrd | 211.48 ns | 1.315 ns | 1.098 ns | 0.0668 | 560 B |
| TransientInstanceCallAsyncMethodWhenCastle | 197.95 ns | 0.657 ns | 0.549 ns | 0.0782 | 656 B |
| TransientInstanceCallAsyncMethodWhenAspectCore | 522.63 ns | 4.313 ns | 4.034 ns | 0.1030 | 864 B |

## License
[MIT](https://github.com/fs7744/Norns.Urd/blob/main/LICENSE)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Norns.Urd.Caching
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true)]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
public class CacheAttribute : Attribute
{
private readonly ICacheOptionGenerator optionGenerator;
Expand Down
2 changes: 1 addition & 1 deletion src/Norns.Urd/DynamicProxy/FacadeProxyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override void CallPropertyInjectInConstructor(in ProxyGeneratorContext
// no call PropertyInject In Constructor
}

protected override FieldBuilder DefineMethodInfoCaller(in ProxyGeneratorContext context, MethodInfo method)
protected override FieldBuilder DefineMethodInfoCaller(in ProxyGeneratorContext context, MethodInfo method, MethodInfo serviceMethod)
{
return context.AssistType.DefineMethodInfoCaller(method, method.GetReflector().DisplayName);
}
Expand Down
8 changes: 7 additions & 1 deletion src/Norns.Urd/DynamicProxy/InheritProxyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected override void CallPropertyInjectInConstructor(in ProxyGeneratorContext
il.Emit(OpCodes.Call, context.ProxyType.PropertyInject.setter);
}

protected override FieldBuilder DefineMethodInfoCaller(in ProxyGeneratorContext context, MethodInfo method)
protected override FieldBuilder DefineMethodInfoCaller(in ProxyGeneratorContext context, MethodInfo method, MethodInfo serviceMethod)
{
var baseMethodName = $"{method.GetReflector().DisplayName}_Base";
if (!context.ProxyType.Methods.TryGetValue(baseMethodName, out var methodBaseBuilder))
Expand All @@ -28,6 +28,12 @@ protected override FieldBuilder DefineMethodInfoCaller(in ProxyGeneratorContext
methodBaseBuilder.DefineGenericParameter(method);
methodBaseBuilder.DefineParameters(method);
methodBaseBuilder.DefineCustomAttributes(method);
var serviceMethodReflector = method.GetReflector();
foreach (var customAttributeData in serviceMethod.CustomAttributes
.Where(i => !i.AttributeType.IsSubclassOf(typeof(AbstractInterceptorAttribute)) && !serviceMethodReflector.IsDefined(i.AttributeType)))
{
methodBaseBuilder.SetCustomAttribute(customAttributeData.DefineCustomAttribute());
}
var il = methodBaseBuilder.GetILGenerator();
if (method.IsAbstract)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Norns.Urd/DynamicProxy/ProxyBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private MethodBuilder DefineMethod(in ProxyGeneratorContext context, MethodInfo

protected abstract void GetServiceInstance(in ProxyGeneratorContext context, ILGenerator il);

protected abstract FieldBuilder DefineMethodInfoCaller(in ProxyGeneratorContext context, MethodInfo method);
protected abstract FieldBuilder DefineMethodInfoCaller(in ProxyGeneratorContext context, MethodInfo method, MethodInfo serviceMethod);

protected abstract void CallPropertyInjectInConstructor(in ProxyGeneratorContext context, ILGenerator il);

Expand All @@ -180,7 +180,7 @@ protected MethodBuilder DefineProxyMethod(in ProxyGeneratorContext context, Meth
methodBuilder.DefineParameters(method);
methodBuilder.DefineCustomAttributes(method);
var il = methodBuilder.GetILGenerator();
var caller = DefineMethodInfoCaller(context, implementationMethod);
var caller = DefineMethodInfoCaller(context, implementationMethod, method);
if (method.ContainsGenericParameters && !method.IsGenericMethodDefinition)
{
il.Emit(OpCodes.Ldsfld, caller);
Expand Down
6 changes: 4 additions & 2 deletions test/Examples.WebApi/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Norns.Urd.Caching;

namespace Examples.WebApi.Controllers
{
public interface IAopTest
{
[Cache(nameof(Get), AbsoluteExpirationRelativeToNow = "00:00:05")]
IEnumerable<WeatherForecast> Get();
}

Expand Down Expand Up @@ -63,10 +65,10 @@ public async Task TestUploadStream()
[HttpGet("file")]
public async Task TestDownloadStream()
{
HttpContext.Response.ContentType = "application/octet-stream";
HttpContext.Response.ContentType = "application/octet-stream";
var bytes = System.Text.Encoding.UTF8.GetBytes(Guid.NewGuid().ToString());
await HttpContext.Response.Body.WriteAsync(bytes, 0, bytes.Length);
await HttpContext.Response.CompleteAsync();
await HttpContext.Response.CompleteAsync();
}
}
}
33 changes: 29 additions & 4 deletions test/Norns.Urd.Test/Caching/MemoryCacheTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ public CacheOptions Generate(AspectContext context)
}
}

public class DoCacheTest
public interface IDoCacheTest
{
[Cache(nameof(DoInterfaceint), AbsoluteExpirationRelativeToNow = "00:00:02")]
int DoInterfaceint(int count);
}

public class DoCacheTest : IDoCacheTest
{
public int Count { get; set; }

[Cache(nameof(DoVoid), AbsoluteExpiration = "00:00:01")]
Expand Down Expand Up @@ -64,15 +70,34 @@ public virtual ValueTask DoValueTaskAsync(int count)
Count = count;
return new ValueTask(Task.CompletedTask);
}
}

public DoCacheTest Mock()
public int DoInterfaceint(int count)
{
return count;
}
}

public T Mock<T>() where T : IDoCacheTest
{
return new ServiceCollection()
.AddTransient<DoCacheTest>()
.AddTransient<IDoCacheTest, DoCacheTest>()
.ConfigureAop(i => i.EnableMemoryCache())
.BuildServiceProvider()
.GetRequiredService<DoCacheTest>();
.GetRequiredService<T>();
}

public DoCacheTest Mock()
{
return Mock<DoCacheTest>();
}

[Fact]
public void CacheWhenInterfaceSyncNoReturnValue()
{
var sut = Mock<IDoCacheTest>();
Assert.Equal(3, sut.DoInterfaceint(3));
Assert.Equal(3, sut.DoInterfaceint(5));
}

[Fact]
Expand Down
14 changes: 14 additions & 0 deletions test/Norns.Urd.Test/DependencyInjection/MethodTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public int DefaultNonAspectIntMethodOutParameter(out int y)
}

int IntMethod();

int IntMethod2();
}

public abstract class MTest
Expand Down Expand Up @@ -84,6 +86,8 @@ public class MMTest : IMTest
{
public int IntMethod() => 6;

int IMTest.IntMethod2() => 88;

[NonAspect]
public virtual int NonAspectIntMethod() => 3;

Expand Down Expand Up @@ -146,6 +150,16 @@ public void InterfaceWhenDefaultNonAspectIntMethodOutParameter()
Assert.Equal(4, y);
}

[Fact]
public void InterfaceWhenPrivateIntMethod2()
{
var p = AopTestExtensions.ConfigServiceCollectionWithAop(i => i.AddTransient<IMTest, MMTest>())
.GetRequiredService<IMTest>();
var pt = p.GetType();
Assert.True(pt.IsProxyType());
Assert.Equal(88, p.IntMethod2());
}

#endregion Interface

#region abstract class
Expand Down

0 comments on commit d126713

Please sign in to comment.