我在我的应用程序中有一个界面(IDomainService)和一个(很多),我用它标记了更多的接口(IProductionLineTitleDuplicationChecker),就像你在其他程序中看到的那样:
public interface IDomainService
{
}public interface IProductionLineTitleDuplicationChecker : IDomainService
{
///
}其实施方式如下:
public class ProductionLineTitleDuplicationChecker : IProductionLineTitleDuplicationChecker
{
private readonly IProductionLineRepository _productionLineRepository;
public ProductionLineTitleDuplicationChecker(IProductionLineRepository productionLineRepository)
{
_productionLineRepository = productionLineRepository;
}
public bool IsDuplicated(string productionLineTitle)
{
///
}
}现在,我使用内置的DI-容器来解析和注册服务,但是我想要更改它,而使用滤过器。
如何使用服务解析和注册授权器?
发布于 2022-11-19 18:47:44
您只需利用Scrutor扩展方法来实现Microsoft.Extensions.DependencyInjection.IServiceCollection。在你的Startup.cs里
public void ConfigureServices(IServiceCollection serviceCollection)
{
serviceCollection
.Scan(x => x.FromAssemblyOf<ProductionLineTitleDuplicationChecker>()
.AddClasses()
.AsImplementedInterfaces()
.WithTransientLifetime());
}发布于 2022-11-21 08:39:21
我认为您的情况与this post是一致的,请尝试使用下面的方式:
services.Scan(scan => scan
.FromAssemblyOf<IProductionLineTitleDuplicationChecker>()
.AddClasses(classes => classes
.AssignableTo<IProductionLineTitleDuplicationChecker>())
.AsImplementedInterfaces()
.WithScopedLifetime());发布于 2022-11-29 20:08:50
我觉得这应该管用
public void ConfigureServices(IServiceCollection serviceCollection)
{
services.Scan(scan => scan
.FromAssemblyOf<IProductionLineTitleDuplicationChecker>()
.AddClasses(classes => classes.AssignableTo<IDomainService>())
.AsImplementedInterfaces()
.WithScopedLifetime());
}https://stackoverflow.com/questions/74502598
复制相似问题