"plugins"폴더에서 어셈블리를로드하고 일부 구현을 동적으로 등록합니다. Autofac + OWIN 서비스 해결 문제
builder.RegisterAssemblyTypes(asms)
.Where(t => typeof(IValidator).IsAssignableFrom(t))
.AsClosedTypesOf(typeof(IValidator<>));
builder.RegisterAssemblyTypes(asms)
.Where(t => typeof(IService).IsAssignableFrom(t) && t.IsClass)
.AsImplementedInterfaces()
.AsSelf();
그냥 내가 모든 등록 로그 확인하기 :
var appPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
var pluginsPath = Path.Combine(appPath, path);
var asmfiles = Directory.EnumerateFiles(pluginsPath, "*.dll", SearchOption.AllDirectories);
foreach(var asmfile in asmfiles)
{
Assembly.LoadFile(asmfile);
}
모든 어셈블리를로드 한 후, 나는 서비스 등록을 진행
container.ComponentRegistry
.Registrations
.SelectMany(x => x.Services)
.Select(x => x.Description)
2016-07-13 09:58:52.5673 TRACE: Registered services:
Services.Test.ITestService
ServiceModel.IService
Services.Test.TestService
2016-07-13 09:58:52.5673 TRACE: Registered validators:
TestRequestValidator
문제를 Autofac 수 없어 생성자에 ITestService
종속성을 가진 컨트롤러를 만드는 것처럼 보입니다.
"type": "Autofac.Core.DependencyResolutionException",
"message": "None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'ApiHostService.Controllers.EchoController' can be invoked with the available services and parameters: Cannot resolve parameter 'Services.Test.ITestService testService' of constructor 'Void .ctor(Services.Test.ITestService)'.",
무엇이 문제 일 수 있습니까?
편집 : 컨테이너에서 해결이 실패합니다.
무슨 일이 직접 컨테이너에서 ITestService를 해결하려고 할 때? –
해결되지 않습니다. – Raine