Actually I just realized part of the problem, my IoC class is using
it's own kernel. I'm still not sure why OnApplicationStarted is not
firing, at least not via debugger. I'm also a bit unsure as to how to
get something from the kernel when it is in the global.asax.cs itself
(presumably I cannot use ctor injection there). I tried the below but
it didn't work:
[DepInject]
public IAppPrincipal Principal { get; set; }
Error activating IAppPrincipal using binding from IAppPrincipal to
method
Provider returned null.
Activation path:
2) Injection of dependency IAppPrincipal into property Principal of
type MvcApplication
1) Request for global_asax
Suggestions:
1) Ensure that the provider handles creation requests properly.
My WebAppModule looks like the below BTW:
internal class WebAppModule : NinjectModule
{
public override void Load()
{
BindSecurityTypes();
}
private void BindSecurityTypes()
{
Bind<IPrincipal>().ToMethod(delegate
{
return HttpContext.Current.User;
});
Bind<IAppPrincipal>().ToMethod(delegate
{
IAppPrincipal prin = null;
var user = HttpContext.Current.User;
// if user is null it means we have not yet got to the
point of the app having the
// session and user identity setup so we bail as we
need WindowsIdentity
// WindowsIdentity.GetCurrent() won't help as it will
be the IIS user
if (null == user)
return null;
EnsureThat.ValueIsNotNull(user.Identity,
"user.Identity");
EnsureThat.StringIsSet(
user.Identity.Name,
"
user.Identity.Name");
var winUser = user.Identity as WindowsIdentity;
EnsureThat.ValueIsNotNull(winUser, "winUser");
prin = new AppPrincipal(winUser);
return prin;
}).InRequestScope();
}
}
On Oct 22, 4:17 pm, Geoff <
thnk...@gmail.com> wrote:
> When I derive from NinjectHttpApplication and override
> OnApplicationStarted, it never seems to fire. Application_Start was
> firing before when inheriting from HttpApplication. I can override
> Init and it will fire but not OnApplicationStarted. So in my
> Application_AuthenticateRequest method where I try to get a type from
> Ninject it will always be null because the kernel was never created.
>
> I can avoid using NinjectHttpApplication and write code to always
> check to ensure the kernel is created but I wanted to try to do this
> the "standard way". I've restarted IIS but I cannot figure out why it
> does not fire.
>
> I am using IIS 7.5 and running from Visual Studio. Project is .net 4
>
ASP.NET MVC. Using 2.2.0.0 version of Ninject.
>
> My app class is below. Any ideas? Thanks
>
> public class MvcApplication : NinjectHttpApplication
> {
> private static bool AppStarted { get; set; }
>
> private void PerformAppStartup()
> {
> if (AppStarted) return;
> AreaRegistration.RegisterAllAreas();
> RegisterGlobalFilters(GlobalFilters.Filters);
> RegisterRoutes(RouteTable.Routes);
> AppStarted = true;
> }
>
> // never seems to fire:
> //
http://stackoverflow.com/questions/2247533/how-do-i-get-ninject-2-0-w...