현재 프로젝트에서 LightInject를 사용하려고하지만 null 값이 계속 나타납니다. MVC 5에 웹 앱이 있고 비즈니스 티어가 첨부되어 있습니다. 웹 프로젝트에 LightInject.Mvc 및 LightInject.Web을 설치했습니다. 내 비즈니스 프로젝트에 LightInject.Mvc을 설치했습니다.ASP.NET MVC 5 및 LightInject
using LightInject;
using SimpleKB.Business.Commands;
namespace SimpleKB.Business
{
public class CompositeRoot : ICompositionRoot
{
public void Compose(IServiceRegistry serviceRegistry)
{
serviceRegistry.Register<IRegisterUserCommand, RegisterUserCommand>();
serviceRegistry.Register<ICreateCategoryCommand, CreateCategoryCommand>();
serviceRegistry.Register<IUpdateCategoryCommand, UpdateCategoryCommand>();
}
}
}
다음, 웹 프로젝트에서 Global.asax.cs, 나는이 (가) app_start 방법으로 다음과 같습니다 :
비즈니스 계층에서 , 나는 compositionRoot.cs 파일이var serviceContainer = new ServiceContainer();
serviceContainer.RegisterFrom<Business.CompositeRoot>();
serviceContainer.EnableMvc();
마지막으로, 내 컨트롤러 코드는 다음과 같습니다
public class AccountController : Controller
{
public IRegisterUserCommand RegisterUserCommand { get; set; }
[HttpGet]
[AllowAnonymous]
public ActionResult Login()
{
RegisterUserCommand.Execute();
return View();
}
}
기본적으로 내가 널 예외를 얻을 컨트롤러가 코드를 사용할 때 RegisterUserCommand. Interface가 발생할 때 LightInject가 자동으로 코드를 주입한다고 가정했습니다. 내가 뭘 놓치고 있니?