Result<T>
このような結果を返すためにメソッドでよく使用するジェネリックジェネリッククラスがあります
public Result<User> ValidateUser(string email, string password)
ILoggingService
サービス注入をログに記録するためのクラスにインターフェイスがありますResult
が、実際の実装を注入する方法が見つかりません。
以下のコードを実行しようとしましたが、TestLoggingService
インスタンスがプロパティに注入されません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
}