Does anyone know how to use an AsyncController in a mvc application that uses Ninject for DI?
AsyncController works fine when i dont use ninject but i cant make them work together.
I added following in my sitemodule but no go.
Bind<IAsyncController>( ).To<AsyncController>( ).InSingletonScope( );
sorry for not explaining this in details.
my controller looks like this
[HandleError]
public class HomeController : AsyncController
{
public void IndexAsync( )
{
AsyncManager.OutstandingOperations.Increment( );
RssFeed feed = new RssFeed( );
feed.GetRssFeedAsyncCompleted += ( s, e ) =>
{
AsyncManager.Parameters[ "items" ] = e.Items;
AsyncManager.OutstandingOperations.Decrement( );
};
feed.GetRssFeedAsync( "http://feeds.abcnews.com/abcnews/topstories" );
}
public ActionResult IndexCompleted( IEnumerable<SyndicationItem> items )
{
ViewData[ "SyndicationItems" ] = items;
return View( );
}
}
and my global.asax looks like this
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
protected void Application_Start( )
{
AreaRegistration.RegisterAllAreas( );
RegisterRoutes( RouteTable.Routes );
}
}
this works fine. but as soon as i use ninject (ninject 2.0 ) i get 404 page not found error when i try to access the index page. this is how i am configuring ninject
public class MvcApplication : NinjectHttpApplication //System.Web.HttpApplication
{
#region IOC
static IKernel container;
public static IKernel Container
{
get
{
if ( container == null ) { container = new StandardKernel( new SiteModule( ) ); }
return container;
}
}
protected override IKernel CreateKernel( )
{
return Container;
}
#endregion
public static void RegisterRoutes( RouteCollection routes )
{
routes.IgnoreRoute( "{resource}.axd/{*pathInfo}" );
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
}
//protected void Application_Start()
//{
// AreaRegistration.RegisterAllAreas();
// RegisterRoutes(RouteTable.Routes);
//}
protected override void OnApplicationStarted( )
{
AreaRegistration.RegisterAllAreas( );
RegisterRoutes( RouteTable.Routes );
}
}
public class SiteModule : NinjectModule
{
public override void Load( )
{
}
}
Do i need to bind anything on my sitemodule?
BTW i am using Jeff Prosise's example which he posted in his blog Here you can download his demo application and try Ninject-ify it :)
Any help appreciated.