I have an application with a GenericHandler and would like to inject dependencies using Unity. No matter what I try I get the error:
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean
I have tried to follow the example at http://geekswithblogs.net/Rhames/archive/2012/09/11/loosely-coupled-.net-cache-provider-using-dependency-injection.aspx.
My constructor for the handler is as follows:
public class GetPerson : IHttpHandler
{
private IPersonRepository repo;
public GetPerson(IPersonRepository repo)
{
this.repo = repo;
}
IPersonRepository is implemented by CachedPersonRepository. CachedPersonRepository wraps the PersonRepository (which is used for DataAccess if an item cannot be found in the cache). Both CachedPersonRepository and PersonRepository are IPersonRepository:
public class CachedPersonRepository : IPersonRepository
{
private ICacheProvider<Person> cacheProvider;
private IPersonRepository personRepository;
public CachedPersonRepository(IPersonRepository personRepository, ICacheProvider<Person> cacheProvider)
{
This IPersonRepository personRepository is parameterless.
ICacheProvider<Person> is implemented by MemcachedCacheProvider<T>:
public class MemcachedCacheProvider<T> : ICacheProvider<T>
{
public T Get(string key, Func<T> retrieveData, DateTime? absoluteExpiry, TimeSpan relativeExpiry)
{
I have tried unsuccessfully to initialise the Unity Container in my Global.asax file Application_Start. DI is new to me and I would very much appreciate any advice on where I'm going wrong.