MVC3アプリケーションでプロパティインジェクションを使用したいと思います。Unity 2をDIコンテナーとして構成しましたが、コンストラクターインジェクションによってすべてが正常に機能しますが、プロパティインジェクションの使用方法がわかりません。[Dependency]属性でプロパティをマークしましたが、機能しません。
public class UnityDependencyResolver : IDependencyResolver
{
IUnityContainer _container;
public UnityDependencyResolver(IUnityContainer container)
{
_container = container;
}
public object GetService(Type serviceType)
{
try
{
return _container.Resolve(serviceType);
}
catch (Exception)
{
return null;
}
}
public IEnumerable<object> GetServices(Type serviceType)
{
try
{
return _container.ResolveAll(serviceType);
}
catch (Exception)
{
return new List<object>();
}
}
}
Global.asaxには、次のものがあります。
var container = new UnityContainer();
var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
section.Configure(container);
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
どんな助けでも大歓迎です。