Search code examples
c#asp.net-coredlln-tier-architectureef-core-2.0

Sharing Data Access Layer DLLs among multiple Projects


We have multiple projects which share same database.We have created DLLs for this data access layer.Now the problem is, in order to share it as DLLs we have kept 3 class libraries(3 layers of database access layer) inside a solution.There may be a scenario in future where data access layer needs some modifications(migrations).So how do keep the database access layer in such a way that it supports future modifications which is not very flexible as of now.

We cannot run migrations in a class library project, One workaround for it could be having a web project and adding 3 class libraries separately in it and then using it for modifications. how good is this approach?

We have kept the database access layer code in a different branch in our repository.What we need is that whenever some changes are made to the branch it should trigger some process which extracts the modified DLLs and add it as a reference in our projects.


Solution

  • The only time you should share a dll across projects is if the projects are really tiny and never change. In the real world, that is never the case and can quickly become unmanagable.

    There are many many ways you could do this. Here are 2 of the better ways you could go about doing this:

    1. put the shared code into a nuget package and host it locally (as easy as setting up a shared folder if you don't have azure)

    2. create a micro service for the shared data and have apis that you call to get the info from each app. Can easily make a nuget package that is a "client" of the microservice and import that into each app instead of copy pasting the connection code in each app.