Develop core classes

We will start by creating a Core folder and defining a few classes, which will be common for all the managers and referenced by all business managers.

IActionManager is the interface that exposes four common methods to perform the CRUD operations. Any manager implementing this interface has to define the implementation for CRUD operations:

    public interface IActionManager 
{
void Create(BaseEntity entity);
void Update(BaseEntity entity);
void Delete(BaseEntity entity);
IEnumerable<BaseEntity> GetAll();
IUnitOfWork UnitOfWork { get; }
void SaveChanges();
}

BaseEntity is our base entity class from which every entity in the common layer is derived.

Next, we will add the abstract BusinessManager class, which will be inherited by all the concrete classes. Currently, this does not have any method defined, but in future, if any abstract methods need to be added, methods can be defined and all the business managers can use them:

    public abstract class BusinessManager 
{
}

We will be injecting the business managers into the service layer. However, in certain scenarios, there could be a requirement to have multiple or all, business managers needed in any service controller class. To handle this scenario, we will develop the BusinessManagerFactory class, inject the instances through constructor injection and expose properties that return the scoped objects to the controller. Here is the BusinessManagerFactory added in our BusinessLayer to provide access to any manager needed at any time:

    public class BusinessManagerFactory   
{
IServiceRequestManager _serviceRequestManager;
ITenantManager _tenantManager;
public BusinessManagerFactory(IServiceRequestManager
serviceRequestManager=null, ITenantManager tenantManager=null)
{
_serviceRequestManager = serviceRequestManager;
_tenantManager = tenantManager;
}

public IServiceRequestManager GetServiceRequestManager()
{
return _serviceRequestManager;
}

public ITenantManager GetTenantManager()
{
return _tenantManager;
}

}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.139.42