I have the following console program. However, the property service is null and the last line in the following code block throws an exception. What I missed?
class Program
{
static void Main(string[] args)
{
container = new UnityContainer();
container.RegisterType<Service.IService, Service.Service>();
container.RegisterType<IC1, C1>();
container.Resolve<Service.IService>();
// var c1 = container.Resolve<IC1>();
c1.Run();
}
[Depenency] C1 c1 { get; set; }
}
public class C1
{
[Depenency] Service.IService service { get; set; }
public void Run()
{
var s = service.GetSomething(); // service is null
Properties have to be
publicto be injected.Indeed they need a public setter. This works: