Question

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.

Was it helpful?

Solution

I think to have solved. I've created a sealed business class with standard logic such as my company have required me. It's a just a IRepository wrapper with some logic. Then, I've created an inheritable business transaction class, where it's a simple UnotOfWork pattern.

That class expose a protected event with event args about which businessObject is being required to load from some UI or similar, so whose inherit from business transaction class can take advantage from this event in order to inject its own "Business rules". BusinessRule is a simple interface with methods about "GetDataRequired" and "SavingDataRequired" that I'll call in my base BusinessObject class every time I execute a CRUD operation.

That's all. It works fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top