Castle.Windsor Dependency Injection で問題が発生しています。関連する Dao を使用して、すべてのサービス レイヤーをコンテナーに登録したいと思います。また、コンストラクター インジェクションの代わりに適切なインジェクションを取得したいと思います。次のコードを実行すると、常に Dao オブジェクトが null であることがわかります。確かに、コンテナの登録に何か問題があります。私はウェブ上で見つけた多くの解決策を読んで試しましたが、結果はありませんでした。
サービス例:
public class DummyBLL : IDummyBLL
{
public IDelegaDao delegaDao { get; set; }
public IUtenteDao utenteDao { get; set; }
public IFunzioneDao funzioneDao { get; set; }
public void dummyMethod(String key)
{
//Business logic that make use of the dao objects
}
...
}
ダオの例:
public class BaseDao<T> : BaseDao where T : Entita
{
public BaseDao()
{
Session = NHibernateHelper.CurrentSession;
}
public BaseDao(ISession session)
{
this.Session = session;
}
}
public class BaseDao
{
public ISession Session { get; protected set; }
public BaseDao()
{
SearchFields = new List<string>();
Session = NHibernateHelper.CurrentSession;
}
public BaseDao(ISession session)
{
if (session != null)
{
Session = session;
}
else
{
Session = NHibernateHelper.CurrentSession;
}
SearchFields = new List<string>();
}
}
public interface IFunzioneDao
{
IEnumerable<COGE.Business.ObjectModel.Funzione> CercaFunzioniPerUtente(Guid idUtente);
IEnumerable<COGE.Business.Data.Dto.FunzioneDto> GetAllFunzioni();
}
public class FunzioneDao : BaseDao<Funzione>, IFunzioneDao
{
public FunzioneDao() { }
public FunzioneDao(ISession session): base(session){}
public IEnumerable<FunzioneDto> GetAllFunzioni()
{
var funzioni = Session.QueryOver<Funzione>()
.OrderBy(x => x.Categoria).Asc
.ThenBy(x => x.Descrizione).Asc
.List();
return funzioni.Select(x => x.ToDto());
}
public class TgcppdcDao : BaseDao, ITgcppdcDao
{
private IDbConnection connessione = null;
private ISession session = null;
private static readonly ILog Log = LogManager.GetLogger(typeof(TgcppdcDao));
public TgcppdcDao()
{
}
public TgcppdcDao(ISession session)
: base(session)
{
}
ジェネリック基本クラスを継承する必要がある dao と、非ジェネリック クラスを必要とするその他の dao があります。
コンテナに登録するには、次のことを行っています。
// service registration
container.Register(Classes.FromAssemblyNamed("COGE.Business").InNamespace("COGE.Business.BLL").WithServiceFirstInterface().LifestyleTransient());
//to register the non generic dao
container.Register(Classes.FromAssemblyNamed("COGE.Business").BasedOn(typeof(BaseDao<>)).WithServiceAllInterfaces().LifestyleTransient());
//to register generic dao
container.Register(Classes.FromAssemblyNamed("COGE.Business").BasedOn(typeof(IBaseGenericDao<>)).WithServiceAllInterfaces().LifestyleTransient());
非ジェネリック dao には問題ありませんが、インジェクションはジェネリック dao では機能しません。
どうすれば問題を解決できますか?
前もって感謝します。