I am trying to make a simple REST Service with .NET 4.0 that uses ninject to inject any dependencies for the service.
This is what my service looks like currently:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class ReportService
{
private readonly ReportManager _reportManager;
public ReportService(ReportManager reportManager)
{
_reportManager = reportManager;
}
[WebInvoke(UriTemplate = "GetReports", Method = "GET")]
public List<ReportDTO> GetReports()
{
var reports = _reportManager.GetReports();
return reports.ToList();
}
}
This is my global.asax:
public class Global : NinjectHttpApplication
{
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
private void RegisterRoutes()
{
RouteTable.Routes.Add(new ServiceRoute("ReportService", new NinjectWebServiceHostFactory(), typeof(ReportService)));
}
protected override IKernel CreateKernel()
{
return new StandardKernel(new ServiceModule());
}
}
And my ServiceModule:
public class ServiceModule : NinjectModule
{
public override void Load()
{
Bind<IFRSDbContext>().To<FRSDbContext>().InRequestScope();
Bind<IDatabaseFactory>().To<DatabaseFactory>().InRequestScope();
Bind<IUnitOfWork>().To<UnitOfWork>().InRequestScope();
Bind<IReportRepository>().To<ReportRepository>();
Bind<ReportManager>().ToSelf();
Bind<ReportService>().ToSelf();
}
}
I keep getting the following exception when I try to run my service:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +222
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253
[HttpException (0x80004005): Object reference not set to an instance of an object.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9079228
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
EDIT
I've updated to the most current version of my Service.. I am using Ninject 2.3 and Ninject.Extensions.Wcf 2.3 from here but am still having no luck.. what am I doing wrong? I've followed everything from the WcfTimeService example except that I am using a REST service and not a .svc Wcf service...