modelsbuilder/ModelsBuilder.Original

Generate models in more than one namespace

Opened this issue · 5 comments

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.

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?

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).

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?

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?

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