1
votes

I have a business logic layer(BLL) and data access layer(DAL). DAL layer is injected as IUnitOfWork into BLL with Unity.

I am doing all DB operations with IUnitOfWork inside BLL but now I need to inject an abstract factory into BLL. One of the factory implementation need to pull some data from database. What I did is to inject IUnitOfWork to that factory in the constructor and factory itself have access to DAL layer. Can you tell me if this is acceptable? Should other classes other than BLL have access to IUnitOfWork? Is this violation of good practices?

1

1 Answers

0
votes

your db operations should be restricted to your DAL layer. what you get is that in your dal layer you have something like

 class MyDBUnitOfWork: IUnitOfWork {

    public void Save(someobject) {/*db operations here */}
    public someobject Load(somequery) { ....}
 }

now in your BLL you have something like this

  class BusinessTransaction {
      public void IncrementSomething(UnityContainer container ) {
           var unitofwork = container.Resolve<IUnitOfWork>();

           var obj = unitofwork.Load(42)
           obj.Prop++;
           unitofwork.Save(obj);
      }
  }

what you see happening here is that IUnitOfWork is probally defined in your BLL (or a separate project defining your interfaces) but is accessible from both your BLL and DAL

your MyDBUnitOfWork is contained within the DAL but the BLL has no knowledge of this. The same goes for your factory. you won't need access to your DAL layer.

Now you need 1 magic place where you register all your implementations with unity so your resolve works. that is the 1 single place that has knowledge of everything.