Im using umbraco v 4.7.1 (Assembly version: 1.0.4281.20201) and have a project where I must extend the global.asax file.
Please not the following
- I have tried this, http://blog.mattbrailsford.com/2010/07/11/registering-an-application-start-event-handler-in-umbraco/, didn’t work in 4.7
- it is Global.asax I need to extend since I’m working with dependency injection
- I cannot delete the App_global.asax.dll file (as some may suggest) since it will regenerate everytime I restart or rebuild my project
Here is my implementation,
using Project.Umbraco.DependencyInjection;
using Project.Umbraco.IoC;
using Microsoft.Practices.Unity;
using System;
using System.Diagnostics;
using umbraco;
namespace Project.Umbraco.App_Start
{
public class MyGlobal : Global, IContainerAccessor
{
///
/// Returns the IoC container
/// IContainerAccessor
///
public IUnityContainer Container
{
get
{
return MvcUnityContainer.Instance.Container;
}
}
protected override void Application_Start(object sender, EventArgs e)
{
base.Application_Start(sender, e);
Debug.WriteLine("Application start");
}
protected override void Application_BeginRequest(object sender, EventArgs e)
{
base.Application_BeginRequest(sender, e);
Debug.WriteLine("Application start");
}
//protected void Session_Start(object sender, EventArgs e) {}
//protected void Application_AuthenticateRequest(object sender, EventArgs e) {}
//protected void Application_Error(object sender, EventArgs e) {}
//protected void Session_End(object sender, EventArgs e) {}
//protected void Application_End(object sender, EventArgs e) {}
}
}
The implementation seems as if should work, maybe I’ve just placed this in the wrong namespace or something?
Thanks for any help
T
From Umbraco 4.8.0 and onwards, the App_global.asax.dll is no longer needed, so you might want to consider upgrading to a newer version.
In 4.7 though, you could simply use the PreApplicationStart method by creating a class that looks a little something like this:
Of course, instead of defining WebAPI routes, you could insert your DI code.