I’ve a WCF Service with BLL, DLL and BE (Business Entities) on separate class libraries.
I would like to use the above BLL, DLL and BE for other project types such as Console Application, Web Application and Azure Worker Roles etc. The reason being all these application use the same data source and some of the same BE.
Could anyone please suggest if the above approach is the best pattern to use? OR should I create separate BLL and DLL on each project type of it’s own.
Thankyou heaps.
There are a couple of ways of sharing the logic:
Reference the DLL in other projects directly. For code that is shared, adjust the output to a shared directory. Compile the shared logic first, and then in project that needs this logic, just add a DLL reference.
Link the source control files. Visual Studio allows to link source control files in other projects. I’ve done a few times, but it can get a little confusing because the source file is linked. To make changes, update the source file in the project that is not linked, then all the projects will be updated as they are linked to the source control file(s).
Implement Contracts via interfaces. Instead of referencing code directly, each BLL, DLL, BE exposes an interface via a Contract DLL. The project that uses the BLL, DLL, BE then references the contract DLL (not the actual DLL directly) and uses the interface. This is a loosely coupled model. To use this, one can use UNITY or MEF or any other type of framework that helps to bind the loosely coupled components together. The nice thing about this is that your code is just sharing the interface and not the actual implementation, so it can change in the future rather easily.
My advice is that if your implementation changes frequently, it is better to go with a loosely coupled system. If sharing logic that will not change, then go for a tighter coupled system with the first two options.