Lee Dale

You m ay have found an issue with the way your solution is structured but in fact I think it's completely unrealistic to expect any decent sized application to not share code across microservices. I think loose coupling is a good goal in general but must be balanced with other considerations. For example we share a domain class library across services and a data access layer along with "interface" libraries that allow us to standardize on known interfaces. Although there are shared dependencies each service is independently deployable because they can depend on different versions of the library, managed by our package feed. Without code reuse the amount of duplicated work would be enormous. You can try to mitigate coupling by considering bounded contexts for each service.

--

--

The factory method is a design pattern that can be used in your .NET projects to support dependency injection and therefore testable classes while also keeping your components decoupled from external dependencies.

You can dive deeper into the uses of the design pattern at the Wikipedia article. The video below shows a simple example of creating a testable class with an external dependency that can be mocked. It then shows how to create a factory class to hide the external dependency from a client component.

--

--

Lee Dale

Lee Dale

I am a lead software developer/cloud architect who has been designing and building software solutions professionally for the last twenty years.