0
나는이 로깅 서비스 주입을위한 ILoggingService
인터페이스 Result
의 클래스는하지만 난 방법을 찾을 수없는이의존성 주입
public Result<User> ValidateUser(string email, string password)
같은 결과를 반환하는 방법에 자주 사용하는 일반적인 Result<T>
제네릭 클래스를 실제 구현을 주입합니다.
아래 코드를 실행하려고했지만 TestLoggingService
intance가 LoggingService
속성에 주입되지 않았습니다. 항상 null을 반환합니다. 어떤 아이디어가 그것을 해결하는 방법?
using (var kernel = new StandardKernel())
{
kernel.Bind<ILoggingService>().To<TestLoggingService>();
var resultClass = new ResultClass();
var exception = new Exception("Test exception");
var testResult = new Result<ResultClass>(exception, "Testing exception", true);
}
public class Result<T>
{
[Inject]
public ILoggingService LoggingService{ private get; set; } //Always get null
protected T result = default(T);
//Code skipped
private void WriteToLog(string messageToLog, object resultToLog, Exception exceptionToLog)
{
LoggingService.Log(....); //Exception here, reference is null
}
해상도 확장이 가능합니까?이 상황에서 도움이 될 수 있습니까? 어디서나 ResolutionExtensions의 메소드에 대한 설명을 찾을 수 없습니다. – Tomas
+1 @Tomas는 답을 읽고 신뢰합니다 - Remo는 그의 추천에서 정확합니다. 당신이 인용하는 방법은'Kernel.Get()'과 같은 것으로 간주되는 것이 가장 좋습니다. –