내 데모 코드는 더 문제가없는 파생 클래스의 DerivedDecorations
은 위의 경우공장 패턴 <T> 문제
에 확인할 수 없습니다
using Microsoft.Practices.Unity;
using System;
public interface IDecorator
{
string GetA();
}
public class Decorations:IDecorator
{
public string GetA()
{
return "temp";
}
}
public class Base
{
}
public class Derive : Base
{
[Dependency]
public IDecorator DerivedDecorations { get; set; }
}
public class Program
{
private static void Main(string[] args)
{
Base bd = new Derive(); // here is the point
var container = new UnityContainer();
container.RegisterType<IDecorator, Decorations>();
container.BuildUp(bd); // bd.DerivedDecorations is null
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
매우 간단합니다
우리는 공장 패턴을 사용하고 있기 때문에 그 이유에 대해 명확하지 않습니다. 어느 누구도 저에게 어떤 이유를 줄 수 있습니까?
왜 그냥 'Derive temp = new Derive(); container.BuildUp (temp); 파생 bd = 임시; ' –
우리는 공장을 사용하기 때문에 .... 코드는 Base b = GetDerived() .... – allencharp