2016-09-03 4 views
0

요청별로 사용 ​​가능한 기본 컨트롤러에 일부 서비스를 등록하려고합니다.lightinject를 사용하여 서비스가 항상 null입니다.

public interface IInstagramApiService 
{ 
} 

public interface IApiServiceConfiguration 
{ 
    string CacheKeyPrefix { get; } 
} 

는 그럼 그럼 내가 너무이 서비스를 등록 할 기본 컨트롤러가이

public class InstagramApiService : IInstagramApiService 
{ 
    IApiServiceConfiguration ApiServiceConfiguration { get; set; } 

    public InstagramApiService(IApiServiceConfiguration apiServiceConfiguration) 
    { 
     ApiServiceConfiguration = apiServiceConfiguration; 
    } 

} 

public class ApiServiceConfiguration : IApiServiceConfiguration 
{ 
    public string CacheKeyPrefix 
    { 
     get; 
     set; 
    } 
} 

의 일부 구체적인 구현이있다;

public class BaseController : Controller 
{ 
    IInstagramApiService InstagramApiService { get; set; }   
} 

그래서 내 응용 프로그램을 시작할 때이 초기화가 있습니다. 나는 BaseControllerInstagramApiService을 확인할 때

var instagramApiServiceConfiguration = new ApiServiceConfiguration() { 
    CacheKeyPrefix = "The Cache Key Prefix", 
}; 

container.Register<IInstagramApiService>((factory) => new InstagramApiService(instagramApiServiceConfiguration), new PerRequestLifeTime()); 

는하지만 항상 null입니다. 이 설정을 올바르게하는 방법은 무엇입니까? 그래서 컨트롤러 내에서 언제든지 InstagramApiService을 사용할 준비가 되셨습니까?

답변

0

밝혀졌습니다. 내 InstagramApiServiceBaseController에 간단한 public 수정자가 누락되었습니다.

public class BaseController : Controller 
{ 
    public IInstagramApiService InstagramApiService { get; set; }   
} 
관련 문제