I have a web application built with ASP.NET CORE 3.1 (using Razor Pages). I'm using Entity Framework Core (code first) for data access. Everything is in the same project, let's call it MyProject.Web.
Now I have to create a console application that will use the same database. My plan is to add it as a new project in the same solution as the web application: MyProject.Console.
Since the console application will use the same database, it seems to me to be a good idea to create yet another project in the solution, MyProject.Data, that will contain the entities and all code used for database access. That way, both the web application and the console application could use the same code for data access.
Is this a good idea?
I already have some problems… My entities have validation implemented as attributes (from System.ComponentModel.DataAnnotations;). However, I also have created a custom validation attribute, and to apply that to an entity I need to have the validation attribute class in MyProject.Data as well. This validation attribute implements the interface IClientModelValidator so that my custom validation can be applied on the client side as well. The IClientModelValidator interface is found in the Microsoft.AspNetCore.Mvc.ModelBinding.Validation namespace. First of all, I don't know how to add the necessary framework (Microsoft.AspNetCore.App) to the project MyProject.Data. Secondly, I seems a bit weird to add that framework anyway, since this is supposed to be a data access project only.
Any suggestions on how to solve this, or if it even is a good idea, are very welcome.