Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the Clean Architect structure, I need to split dbcontext and entities into multiple projects. #2283

Closed
WalterB-MAMC opened this issue Apr 16, 2024 · 11 comments
Labels
question Further information is requested

Comments

@WalterB-MAMC
Copy link

WalterB-MAMC commented Apr 16, 2024

Using the Clean Architecture I need to split the output of this tool into multiple projects and reference them from each project. So, let's say that I am going to put the entities in myApp.Domain project and the DBContext and Configurations in the myApp.Infrastructure project. Here I will need to have the DBContext and the Configuraiton files refernece @Using myApp.Infrastructure.Entities when using a sub namespace for the entities. Right now I can run the tool on both projects but then, I have to go into each file and manually change all the references.

This being a popular architecture, among others that split this up, is there a way that the tool can allow for different projects and add the references as needed?

@ErikEJ
Copy link
Owner

ErikEJ commented Apr 17, 2024

Popular? I think you can run the Tool once specifying the individual physical paths.

At any rate in order to help I need a runnable repro as requested when you created this issue.

@WalterB-MAMC
Copy link
Author

Not sure what I would put in a runnable repo as this is just a case of specifying where to put the files that the tool creates.

myApp.Domain
|--Entities
|  |-Movies.cs
|  |-Rentals.cs
|
myApp.Infrastructure
|--Data
|  |-dbContext.cs
|  |-Configurations
|    |-MoviesConfiguration.cs
|    |-RentalsConfiguration.cs

Now when I run the tool how can you get it to put the dbContext and the Configuration files in the myApp.Infrastructure project in the solution and then put the entities in the myApp.Domain project. If I add myApp.Domain.Entities when I run the tool from the Infrastructure project it will put the file in the myApp.Infrastructure.myApp.Domain.Entities folder that it will create. It does not understand that there are multiple projects in the solution.

Hope that helps, if not let me know.

Thanks.

@ErikEJ
Copy link
Owner

ErikEJ commented Apr 17, 2024

Are you running the tool once or twice?

Also suggest you read the wiki docs for this advanced topic on file placement

@WalterB-MAMC
Copy link
Author

The only way I can figure it out is to run it twice, once in the domain project, so that I can get the entities in the domain project and the run it again in the infrastructure project to get the dbcontext and the configuration files in the infrastructure project. If there is a way to run it once and have it put some files in one project and then put the other files in another project, I would love to know what the secret is. I looked at the wiki, but it is very limited on what all the options are for like the sub-namespaces and stuff. I did not find a way to do it. If I missed it, then I would love to know the secret.

@ErikEJ
Copy link
Owner

ErikEJ commented Apr 17, 2024

You need to run it only once
Did you not see the extensive examples in the wiki?

@WalterB-MAMC
Copy link
Author

I have been up and down the wiki and have not seen anything for splitting file outputs to two different projects in one solution. I must not know what I am looking for to find what I am trying to do if you say it is there. Do you have a link to where in the wiki this is at?

@ErikEJ
Copy link
Owner

ErikEJ commented Apr 17, 2024

@WalterB-MAMC
Copy link
Author

That only works in the project that the tool is ran in. Because in the efpt.config.json file there is only one place for the project root namespace, "ProjectRootNamespace": "myApp.Infrastructure". If the files are seperated into two different projects in the solution this stops me from saying put the entities in project A and the dbContext and Configurations in project B. This also does not allow for the @Using myApp.Domain.Entities to be added to the dbContext or Configuration files as again the project root namespace is used, and sub-namespaces are appended to this.

For this to work we would need to add the ability to select the project to add the entities and dbContext and Configuration files to. Either by a dropdown box with the Project names or a textbox to type it in freely. Then the tools would need to make sure it adds the right @Using paths to the files as needed. Then we can use this tool to separate items as we see fit within the solution with multiple projects.

Hopefully this makes sense now and thanks for your help with the link.

@ErikEJ
Copy link
Owner

ErikEJ commented Apr 18, 2024

You can set namespace both for entity classes and DbContext classes.

I need a full repro in order to help you further.

@WalterB-MAMC
Copy link
Author

Ok, I figured out how to get the namespaces to work so that I can point to the right locations in my solution. The only issue is that you cannot just run this one time in the solution, it has to be ran twice, once in each project because I am splitting the models/entities in one project and then the dbContext and configurations in another project. I cannot figure out how it would run once and split this since it seems the tool is project oriented and not solution oriented.

Unless you know of a way to do this, I think it is a limitation of the tool. All you have to do is create a solution with two projects and then try to have the tool separate the items out like I have said and write to both projects. For now, I will just move on as I figured out something that was going to make me touch all the configuration files every time, I regenerated the files by running the reverse engineer process.

@ErikEJ ErikEJ closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2024
@ErikEJ ErikEJ added the question Further information is requested label Apr 19, 2024
@ErikEJ
Copy link
Owner

ErikEJ commented Apr 19, 2024

Cool.

If you like my free tools, I would be very grateful for a rating or review on Visual Studio Marketplace or even a one-time or monthly sponsorship

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants