I'm new to Agatha but the Request/Response pattern as presented is overwhelmingly compelling and very well done.
I have a web app global configuration file as follows:
namespace RequestResponse
{
using System;
using System.Reflection;
using System.Web;
using Agatha.Common;
using Agatha.ServiceLayer;
using Agatha.Unity;
using Services.Requests;
public class Global : HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
InitializeAgatha();
}
private static void InitializeAgatha()
{
var containerImplementation = typeof(Container);
var requestsAndResponsesAssembly = typeof(HelloWorldRequest).Assembly;
var requestHandlersAssembly = Assembly.GetExecutingAssembly();
new ClientConfiguration(requestsAndResponsesAssembly, containerImplementation).Initialize();
new ServiceLayerConfiguration(
requestHandlersAssembly,
requestsAndResponsesAssembly,
containerImplementation).Initialize();
}
}
}
That's all great and I got the HelloWorld sample running no worries.
But I have registrations in an existing application that uses Entity Framework, Repositories, UnitOfWork (the usual). That currently gets injected like this:
namespace RequestResponse
{
using System.Data.Entity;
using Contracts;
using Data;
using Microsoft.Practices.Unity;
using Repository;
public static class CompositionRoot
{
private static readonly IUnityContainer UnityContainer = new UnityContainer();
public static IUnityContainer Container
{
get
{
return UnityContainer;
}
}
public static void RegisterServices()
{
UnityContainer
.RegisterType(typeof(IRepository<>), typeof(GenericRepository<>))
.RegisterType(typeof(IUnitOfWork), typeof(UnitOfWork))
.RegisterType(typeof(DbContext), typeof(DataContext))
.RegisterInstance(new DbContextAdapter(UnityContainer.Resolve<DbContext>()), new PerRequestLifetimeManager())
.RegisterType<IObjectSetFactory>(new InjectionFactory(p => p.Resolve<DbContextAdapter>()))
.RegisterType<IObjectContext>(new InjectionFactory(p => p.Resolve<DbContextAdapter>()));
}
}
}
I need to use the Agatha Unity container but how can I get it to play nice with my above registrations? I think the existing container methods won't work and I can't work out how to get a direct reference through to the UnityContainer (hope that makes sense).
Any ideas?
Thank you,
Richard