dotnetcore/AspectCore-Framework

兄弟,文档不更新都是坑啊

LightCHY opened this issue · 7 comments

新版本的方法,使用都改了,文档没跟,使用者踩着坑,浪费时间啊!
var container = services.ToServiceContainer();
return container.Build();
看例子的这些都没法用........

LGinC commented

.net 5 项目表示都不知道怎么替换默认依赖注入了

LGinC commented

找到了,在IHostBuilder调用UseServiceContext扩展方法(在AspectCore.Extensions.Hosting 包中)
image
在Controller里注入还需要在AddControllers时调用AddControllersAsServices
image

经测试属性注入正常

例子都还是.net core 2的,我更新到.net 5

我發現屬性或是方法都沒有寫註解.... 有人知道是為甚麼嗎?

确实,看文档看了一小时,下载Nuget包准备用的时候,满满的挫败感

确实,看文档看了一小时,下载Nuget包准备用的时候,满满的挫败感

你的具体问题是啥呢

确实,看文档看了一小时,下载Nuget包准备用的时候,满满的挫败感

你的具体问题是啥呢

不好意思,今天才回复。在asp.net中确实尝试成功了

Program.cs

using AspectCore.Extensions.DependencyInjection;
using AspectDemo.WebApplication1.Services;
using Microsoft.AspNetCore.Mvc;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddTransient<IDemoService, DemoService>();
builder.Services.ConfigureDynamicProxy();

builder.Host.UseServiceProviderFactory(new DynamicProxyServiceProviderFactory());
var app = builder.Build();

app.UseRouting();

app.MapGet("/", () => "hi");

app.MapGet("/id", ([FromServices]IDemoService service) => service.GeneratorId());

app.Run();

IDemoService.cs

public interface IDemoService
{
    [Log]
    string GeneratorId();
}

public class LogAttribute : AbstractInterceptorAttribute
{
    public override async Task Invoke(AspectContext context, AspectDelegate next)
    {
        var watch = Stopwatch.StartNew();
        await next(context);
        watch.Stop();
        Console.WriteLine($"{context.ProxyMethod.Name} invoke time-consuming:{watch.Elapsed}ms");
    }
}

但是在控制台程序或WPF、WinForm上,AOP相关代码一直不执行,示例太少,也不知道哪里没配置好