我有通用的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
}