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

Generate models in more than one namespace #219

Open
zpqrtbnk opened this issue Sep 12, 2019 · 5 comments
Open

Generate models in more than one namespace #219

zpqrtbnk opened this issue Sep 12, 2019 · 5 comments
Labels
type/discuss Discussion, Question

Comments

@zpqrtbnk
Copy link
Collaborator

See this discussion on Our

I meant I'd like to generate models into different namespaces

Creating this issue to discuss what that means exactly.

@zpqrtbnk zpqrtbnk added the type/discuss Discussion, Question label Sep 12, 2019
@zpqrtbnk
Copy link
Collaborator Author

Can we elaborate here on the use cases, but what would it do exactly?

Would it be something like...

  • My.Models.Home
  • My.Models.Page
  • My.OtherModels.Product
  • My.OtherModels.Engine

And then... how would the decision to put a model in this or that namespace be made?

For base classes the plan is to be able to fine-tune base-classes per content type alias. Would the same idea work here?

@nathanwoulfe
Copy link

From how I see my use case developing, I'd like to be able to generate models into different namespaces like Models.Grid, Models.ContentTypes, Models.ContentElements and so on, to help maintain a sensible structure when extending those models with partials - given the large number of models I'm dealing with (150+), I'd like to be able to maintain a folder structure in my models project rather than swimming through a lengthy list of files. Also helps manage potential naming collisions too.

I guess I could always create view models derived from the generated models, but that doesn't feel right since the generated models are essentially view models, so should be extending with partials (which is the intent behind generated models being partials, right?)

I'm not across the inner workings of how MB discovers and manages partials, but would it be possible that the process applied the same namespace to the generated model as it finds on the partial, and defaults to the namespace from config when no partial exists? Would be good to avoid explicit configuration (ie a stack of partials existing purely to namespace generated models).

@sniffdk
Copy link

sniffdk commented Sep 12, 2019

I guess it would be quite a lot of work to not have models in the same namespace, when that is just a built in #C thing.
Perhaps instead a way to just generate models in a configurable folder structure but still keep them all with the same namespace?

@zpqrtbnk
Copy link
Collaborator Author

So, two things here: (1) models in different namespaces and (2) models in different folders

Both are quite interesting features, even though I need to think about the details ;-)

Models in different folders... would be problematic for the Visual Studio Extensions, which at the moment generates models as "nested files" under a placeholder file - but that could be changed to simply generate models in a folder. Might even be cleaner.

I guess the key thing here is, how do we determine the namespace / folder for a model.

I totally like the idea of detecting existing partials. Well, we already do detect them, so just picking the namespace and file location from them would be easy. Of course... you could have 2 partials with the same name in 2 different namespace, and we'd need some help to figure things out... but it probably can be done.

But as you write, we want to avoid explicit configuration of everything - which means we want rules in order to figure out what should go where. Can you envision a non-too-crazy rules set which would allow us to determine a folder / namespace for a content type? Based upon the alias... a container folder... something?

@sniffdk
Copy link

sniffdk commented Sep 12, 2019

Based on container folder name would actually be pretty nice, wouldn't mind that at all looking at how I structure my doc types now.
But I guess that would have to be an option in the MB configuration.

Personally, I don't mind having all models in the same namespace, that is a nonissue for me.
Would still put custom partials in an "Extended" folder next to the Models/Generated folder though.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/discuss Discussion, Question
Projects
None yet
Development

No branches or pull requests

3 participants