Pattern: Shared Library (Nugetization)
Description
The Shared Library pattern involves extracting reusable business logic, utilities, or contracts from the Monolithic application into separate Class Library projects that are then packaged and distributed as NuGet Packages.
In the context of WepNG, this is the primary strategy for sharing the Kernel between the Legacy Monolith and the New Microservices.
Context in WepNG
- Candidates:
Common,EITWEP.WepUtils,EITWEP.Model(DTOs only). - Strategy: Instead of referencing projects by File Path (
..\EITWEP.Common\EITWEP.Common.csproj), we publishEITWEP.Commonto an internal NuGet feed (Azure Artifacts / GitHub Packages) and reference it by version (e.g.,1.0.4).
Benefits
- Versioned Contract: The Monolith can run on
v1.2while the new Service testsv2.0. - Decoupling: Forces "Physical Separation". You cannot accidentally call a method in
OMGTfromCommonifCommonis a compiled NuGet package. - Reuse: Enables new .NET 8 Apps to use existing logic without duplicating code.
Risks
- DLL Hell: Managing transitive dependencies (e.g.,
Commondepends onNewtonsoft v10butWepAPIneedsv13). - Development Friction: Changing a shared library requires: Code -> Commit -> Build -> Push NuGet -> Update Package in Main App.
- Mitigation: Use "Project References" locally during development, switch to NuGet for Release.