modelsbuilder/ModelsBuilder.Original

Allow manually defined models to override PureLive models

Opened this issue · 2 comments

I'm looking to create a Starter Kit for Umbraco however my Starter Kit is going to need some SurfaceControllers and in those controllers it will need access to the MB models. Unfortunately, PureLive models are available in a controller context.

This in itself isn't a problem as I'd happily create the models myself manually and allow them to be distributed with the Starter Kit, however, the problem is that there is no way to override PureLive models with your own predefined models. As the Starter Kit will be installed on a solution we won't know the models builder mode of (or, I don't really want to have to change this for them), it would be good if there was a way to use PureLive by default, but for things I want to control in my Starter Kit provide predefined classes that would work in controllers too, but would be used by Models Builder in place of the dynamic PureLive models.

Isn't this already possible if you create custom interfaces, use those in your own controllers and ship partial classes (in ~\App_Data\Models) to make the generated models implement those?

You can also disable generation of the document type using [assembly:IgnoreContentType("alias")], but that would totally break editing the document type, as your shipped model class won't be updated when properties are added, updated or removed...

You also have to account for different namespaces, even when using interfaces and ship partial classes.

Having an assembly attribute to add an interface to a model based on the alias would fix that problem, e.g.: [assembly:ModelsInterface("alias", typeof (IMyOwnInterface))].