I'm developing an application by modules. Each module correspond to a legacy system we have here in the company. Using a code like this, I can inject the Controllers from a Class Library into an MVC Application using Unity Container:
using System.Linq;
using System.Web.Mvc;
using Microsoft.Practices.Unity.Mvc;
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(MyProject.Common.UnityMvcActivator), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethod(typeof(MyProject.Common.UnityMvcActivator), "Shutdown")]
namespace MyProject.Common
{
public static class UnityMvcActivator
{
/// <summary>Integrates Unity when the application starts.</summary>
public static void Start()
{
var container = UnityConfig.GetConfiguredContainer();
FilterProviders.Providers.Remove(FilterProviders.Providers.OfType<FilterAttributeFilterProvider>().First());
FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container));
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
// TODO: Uncomment if you want to use PerRequestLifetimeManager
// Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));
}
/// <summary>Disposes the Unity container when the application is shut down.</summary>
public static void Shutdown()
{
var container = UnityConfig.GetConfiguredContainer();
container.Dispose();
}
}
}
This code is automatically added in the Class Library when I install the Unity.Mvc bootstrapper.
All the Class Libraries implemented as modules will be web-oriented.
Works like a charm, but I still have to define all the routes in the RouteConfig
from the MVC Application. My challenge is to define these routes in the class library. I haven't found any material explaning how to do.
Is this possible? If yes, how?