WCF Ninject 확장을 사용하여 WCF 서비스에 Ninject를 추가하려고합니다.WCF/Ninject/Default (매개 변수가없는) 생성자
<%@ ServiceHost Language="C#" Debug="true" CodeBehind="SchedulingSvc.svc.cs"
Service="Scheduling.SchedulingSvc"
Factory="Ninject.Extensions.Wcf.NinjectWebServiceHostFactory" %>
Global.asax 파일이 NinjectHttpApplication에서 상속 및 CreateKernel이있는 새로운 커널을 반환
The service type provided could not be loaded as a service because it does not have a default (parameter-less) constructor. To fix the problem, add a default constructor to the type, or pass an instance of the type to the host.
서비스는 Ninject에 서비스 호스트 공장이 있습니다
나는 오류를 받고 있어요 NinjectModule :
public class Global : NinjectHttpApplication
{
protected override IKernel CreateKernel()
{
return new StandardKernel(new NinjectServiceModule());
}
}
NinjectModule :
public class NinjectServiceModule : NinjectModule
{
public override void Load()
{
this.Bind<ISchedulingService>().To<SchedulingSvc>();
this.Bind<ISchedulingBusiness>().To<SchedulingBusiness>();
}
}
생성자 주입과 서비스 :
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SchedulingSvc : ISchedulingService
{
private ISchedulingBusiness _SchedulingBusiness = null;
public SchedulingSvc(ISchedulingBusiness business)
{
_SchedulingBusiness = business;
}
public CalendarEvent[] GetCalendarEvents()
{
var calendarEvents = _SchedulingBusiness.GetCalendarEvents();
return calendarEvents;
}
...
}
속성 분사 서비스 : 나는 생성자 분사를 사용하는 경우
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SchedulingSvc : ISchedulingService
{
[Inject] public ISchedulingBusiness _SchedulingBusiness { get; set; }
public SchedulingSvc()
{
}
public CalendarEvent[] GetCalendarEvents()
{
var calendarEvents = _SchedulingBusiness.GetCalendarEvents();
return calendarEvents;
}
...
}
, 나는 게시물의 상단에 언급 된 오류 . 속성 삽입을 사용하려고하면 _ScheduleBusiness는 항상 null입니다.
무엇이 누락 되었습니까?
'SchedulingBusiness'에 대한 모든 필수 종속성을 등록 했습니까? – mipe34
@ mipe34 예. Ninject를 사용하여 비즈니스를 콘솔 앱에 연결하면 예상대로 작동합니다. –