I am trying to use following example provided in Microsoft site. gives compile time error while resolving by type.
http://msdn.microsoft.com/en-us/library/vstudio/hh323725(v=vs.100).aspx
is it issue in the code, how to solve this?
public class DependencyInjectionInstanceProvider : IInstanceProvider
{
private readonly Type _ServiceType;
public DependencyInjectionInstanceProvider(Type serviceType)
{
_ServiceType = serviceType;
}
public object GetInstance(InstanceContext instanceContext)
{
return GetInstance(instanceContext, null);
}
public object GetInstance(InstanceContext instanceContext, Message message)
{
return DependencyFactory.Resolve(_ServiceType); //error
}
public void ReleaseInstance(InstanceContext instanceContext, object instance)
{
}
}
public class DependencyFactory
{
private static IUnityContainer _container;
public static IUnityContainer Container
{
get
{
return _container;
}
private set
{
_container = value;
}
}
static DependencyFactory()
{
var container = new UnityContainer();
var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
if (section != null)
{
section.Configure(container);
}
_container = container;
}
public static T Resolve<T>()
{
T ret = default(T);
if (Container.IsRegistered(typeof(T)))
{
ret = Container.Resolve<T>();
}
return ret;
}
}