I'm building a three tier application such as DAL, BLL, UI layers. DAL expose an EF wrapper (UnitOfWork and Generic Repository pattern).
BLL component is a DAL wrapper with some basic business logic rules. Essentially, BLL expose a BusinessObjectBase class (T is POCO class) with virtual CRUD and validation methods, then a BusinessTransactionBase to coordinate more then one CRUD operations.
You can look at BLL component just like a sort of ObjectContext Wrapper: BusinessObject = ObjectSet with business logic per entity. BusinessTransaction = ObjectContext with some other minimal logic
Also, primary goal of my component is to offer a set of basic logic for different projects. Today I can use my assembly to build an application about MusicStore, tomorrow I could build an application about document management, but always I'll want use my base component (BLL)
Simple snippet:
public class BusinessObjectBase<T> where T : class
{
// protected IUnitOfWork ?
public virtual void Insert(T item)
{
// my default company logic rule..
if(this.Validate(item))
{
IUnitOfWork.GetRepository<T>().AddEntity<T>();
IUnitOfWork.Save();
}
}
public virtual void Edit(T item)
{
// my default company logic rule..
}
public virtual bool Validate(T item)
{
// my default company logic rule..
return true;
}
}
public class BusinessTransactionBase
{
// protected IUnitOfWork ?
public void BeingTransaction()
{
// ... Notify at all BusinessObjectBase to skip IUniOfWork.Save call
}
public void Commit()
{
this.IUnitOfWork.Save();
}
public BusinessObjectBase<T> GetBusinessObject<T>() where T : class
{
// How can I create an instance via reflection of an inherited class
// without to know ctor parameters?
}
}
Well, I've two question:
1) How can I be assured to properly build a BusinessObjectBase on GetBusinessObject method? I'll should build an inhertied object form my base class and I'have not idea about any ctor parameter.
2) How can I be assured about IUnitOfWork sharing between BusinessTransactionBase and BusinessObjectBase class? I'm enforce to do that, because how can I already said, BusinessObjectBase and BusinessTransactionBase are tightly related.