Dependent injection – traditional 3-layer architecture with 3 layers of IOC

I am building a 3-tier architecture with presentation layer (PL), business logic layer (BLL) and data access layer (DAL).
Traditional 3-tier architecture The logic indicates that BLL should act as an intermediary between PL and DAL. PL should not know that there is a database, and DAL should not know that there is a BLL or PL.

The above implementation will be in 3 different physics Create the following dependencies between projects, as shown below

  • PL Project -> Reference of BLL DLL
  • BLL Project -> Reference of DAL DLL
  • DAL Project -> No Reference

However, by defining the interface in BLL to achieve and using DI through constructor injection, Applying the concept of IOC between BLL and DAL will change the dependency relationship, as shown below

  • PL Project -> Reference of BLL DLL, Reference of DAL DLL (for DI of concrete types to constructors of the BLL Objects)
  • BLL Project -> No Reference
  • DAL Project -> Reference of BLL DLL (for implementation of BLL Interfaces)< /li>

Is it the same for the IOC and the traditional three-tier conflict?

Ideally, I hope to achieve the following goals while maintaining my IOC with DI.

  • PL Project -> Reference of BLL DLL
  • BLL Project -> No Reference
  • DAL Project -> Reference of BLL DLL

You How to do this?

First, you can consider using interfaces to decouple layers, and you can separate interfaces into separate Dll. In this way, each layer only depends on the interface of the lower layer.

I am not sure why you need coupling from DAL to BLL? Is this a call back? Can’t you use events?

Assuming all 3 layers are running, and assuming that your PL is the “entry point” of your application (combined root), then IMO the usual dependencies If you have used the boot code in the PL Separate the interface, then:

> PL => reference BLL and DAL (specific and interface) and IoC container
> BLL refers to DAL (or just interface, if applicable)
> DAL There is no dependency (although it usually depends on DTO/POCO/Entities)

PL can offload the IoC configuration to the Bootstrapper dll, resulting in:

> PL => reference the BLL interface and Bootstrapper
> Bootstrapper => Reference to everything and IoC container
> BLL => Reference to DAL interface
> DAL => No dependencies (though usually dependent on DTO/POCO/Entities)

For some containers, you can avoid the requirement to reference all dlls from the bootloader before using configuration, or convention. However, these dlls obviously still need to be deployed with your application.

I am building a 3-tier architecture with presentation layer (PL), business logic layer (BLL) and data access layer (DAL).
The traditional 3-tier architecture logic suggests that BLL should Acting as an intermediary between PL and DAL. PL should not know that there is a database, and DAL should not know that there is a BLL or PL.

The above implementation will be created between 3 different physical projects The following dependencies are as follows

  • PL Project -> Reference of BLL DLL
  • BLL Project -> Reference of DAL DLL
  • DAL Project -> No Reference

However, by defining the interface in BLL to achieve and using DI through constructor injection, in BLL and DAL The application of the concept of IOC will change the dependency relationship, as shown below

  • PL Project -> Reference of BLL DLL, Reference of DAL DLL (for DI of c oncrete types to constructors of the BLL Objects)
  • BLL Project -> No Reference
  • DAL Project -> Reference of BLL DLL (for implementation of BLL Interfaces)

Is it the same for the IOC and the traditional three-tier conflict?

Ideally, I hope to achieve the following goals while maintaining my IOC with DI.

  • PL Project -> Reference of BLL DLL
  • BLL Project -> No Reference
  • DAL Project -> Reference of BLL DLL

You How to do this?

First, you can consider using interfaces to decouple the layers, and you can separate the interfaces into separate dlls. In this way, each layer only depends on the following Layer interface.

I am not sure why you need coupling from DAL to BLL? Is this a call back? Can’t you use events?

Assuming all 3 layers are running, and assuming that your PL is the “entry point” of your application (combined root), then IMO the usual dependencies If you have used the boot code in the PL Separate the interface, then:

> PL => reference BLL and DAL (specific and interface) and IoC container
> BLL refers to DAL (or just interface, if applicable)
> DAL There is no dependency (although it usually depends on DTO/POCO/Entities)

PL can offload the IoC configuration to the Bootstrapper dll, resulting in:

> PL => reference the BLL interface and Bootstrapper
> Bootstrapper => Reference to everything and IoC container
> BLL => Reference to DAL interface
> DAL => No dependencies (though usually dependent on DTO/POCO/Entities)

For some containers, you can avoid the requirement to reference all dlls from the bootloader before using configuration, or convention. However, these dlls obviously still need to be deployed with your application.

Leave a Comment

Your email address will not be published.