Is it possible to enter a type in a constructor instead of an instance? If so, how is this achieved? I want to avoid explicitly registering the factory method or, if possible, resolving the instance in place.
public interface IJob { }
public class TheJob : IJob { }
public interface IService
{
string GetTypeDesc();
}
public class Service : IService
{
private Type _jobType;
public Service(Type jobType)
{
_jobType = jobType;
}
public string GetTypeDesc()
{
return _jobType.ToString();
}
}
It seems that even when registering a type with an explicit constructor definition, Unity wants to insert an instance into the type holder.
Type jobType = typeof(TheJob);
(new UnityContainer()).RegisterType<IService, Service>(new InjectionConstructor(jobType));
source
share