I am just starting to think about the best way to build a site with models builder - and i am thinking about how deployment of the site might work once it's built.
lets assume that i have my build and deployment steps sorted - everything is nugetted and i can get my site and all the files onto a server - and thats all fine.
I am also going to extend the models classes a bit (ala lars-erik's blog excellent blog post) - so i am going to have partials of the model classes in my solution.
So i am looking at the different models for options
Using PureLive Mode - the site won't compile, because the partial classes will be refrencing code that isn't there at build time.
Using DllMode - I get
More that one type want to be a model for content type contentPage. as an error when i have partials in the project. and it doesn't give me anything inside visual studio in terms of internalise.
Also i would have to ensure that dll (which isn't part of the solutions build or a nuget thing) is included in any deployments i do and is included in source control (currently the bin folder isn't in source control, because it doesn't have anything i can't generate with nuget/build in it).
using AppData (and moving the folder to app_code) - This works the best, but i need to make sure the generated files in my project to ensure they get deployed.
So I am wondering if anyone else has nice methods for using models builder and deployments ?
I always use the "Nothing" mode and generate my models via the Visual Studio Extension. That way, all my classes are part of the project. I can check them before deploying and that all my views will run correctly.
With regards to deployment, as they have already been compiled I don't really need to worry about how they are deployed. They are already part of the compiled assembly pushed to the environment.
Then within a directory called PublishedContentModels I have a Builder.cs class which is just an empty class bound to the Custom Tool "UmbracoModelsBuilder".
Once the connection info is set in the Models Builder Extension (Tools/Options/Umbraco) right-clicking on the Builder.cs will generate my models. As Dan says above, this puts the classes within the project allowing them to be deployed with the project. I keep Umbraco Models separate from regular Models for cleanness.
If I want to add some feature to the doctype outside of Umbraco then I'll add a partial class inside PublishedContentModels and add the feature to it. This removes the need to intercept requests with custom MVC Controllers for simple things (I still use custom controllers for complex things though).
Within Umbraco, I have a Base doctype which all other doctypes derive. This acts as my superclass when the models builder does it's work and this gives me the freedom to attach site-wide functions to it. It also means I can have a layout master template inheriting this type:
@inherits UmbracoTemplatePage<Base>
whilst a regular page can inherit its own type
@inherits UmbracoTemplatePage<Home>
avoiding any annoying "cannot cast to type" issues that I used to get back in the day when creating my own custom MVC controllers as Home is a subtype of Base (plus I can attach things like SEO properties to the Base class and make available site-wide).
Finally the property converters nuget package convert 90% of the properties I use to lovely inflated properties on my strongly typed classes. I'll create custom property converters for the remaining 10% if I need them.
I'm sure others implement this differently, the models builder is extremely flexible. You'll play about with it for a while and come to a pattern you enjoy.
Deploying Models builder
Hi,
I am just starting to think about the best way to build a site with models builder - and i am thinking about how deployment of the site might work once it's built.
lets assume that i have my build and deployment steps sorted - everything is nugetted and i can get my site and all the files onto a server - and thats all fine.
I am also going to extend the models classes a bit (ala lars-erik's blog excellent blog post) - so i am going to have partials of the model classes in my solution.
So i am looking at the different models for options
Using PureLive Mode - the site won't compile, because the partial classes will be refrencing code that isn't there at build time.
Using DllMode - I get
More that one type want to be a model for content type contentPage.
as an error when i have partials in the project. and it doesn't give me anything inside visual studio in terms of internalise.Also i would have to ensure that dll (which isn't part of the solutions build or a nuget thing) is included in any deployments i do and is included in source control (currently the bin folder isn't in source control, because it doesn't have anything i can't generate with nuget/build in it).
using AppData (and moving the folder to app_code) - This works the best, but i need to make sure the generated files in my project to ensure they get deployed.
So I am wondering if anyone else has nice methods for using models builder and deployments ?
Hello,
I always use the API Models setup. So the models are generated directly into your extension project and part of your source code and the dll you deploy. More info can be read here: http://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/
Jeroen
Hey Kevin,
I always use the "Nothing" mode and generate my models via the Visual Studio Extension. That way, all my classes are part of the project. I can check them before deploying and that all my views will run correctly.
With regards to deployment, as they have already been compiled I don't really need to worry about how they are deployed. They are already part of the compiled assembly pushed to the environment.
Hope that helps.
Dan.
Thanks ,
I sort of suspected the Visual Studio Extension might be the answer : )
AppData moved to app_code is almost there, but the extension will probably fit better into a workflow for development.
I've been using the models builder for some time now and finally settled on a pattern that I enjoy using.
I install both the Models Builder API and the Models Builder VS Extension then I set the following in my web.config:
Then within a directory called PublishedContentModels I have a Builder.cs class which is just an empty class bound to the Custom Tool "UmbracoModelsBuilder".
Once the connection info is set in the Models Builder Extension (Tools/Options/Umbraco) right-clicking on the Builder.cs will generate my models. As Dan says above, this puts the classes within the project allowing them to be deployed with the project. I keep Umbraco Models separate from regular Models for cleanness.
If I want to add some feature to the doctype outside of Umbraco then I'll add a partial class inside PublishedContentModels and add the feature to it. This removes the need to intercept requests with custom MVC Controllers for simple things (I still use custom controllers for complex things though).
Within Umbraco, I have a Base doctype which all other doctypes derive. This acts as my superclass when the models builder does it's work and this gives me the freedom to attach site-wide functions to it. It also means I can have a layout master template inheriting this type:
whilst a regular page can inherit its own type
avoiding any annoying "cannot cast to type" issues that I used to get back in the day when creating my own custom MVC controllers as Home is a subtype of Base (plus I can attach things like SEO properties to the Base class and make available site-wide).
Finally the property converters nuget package convert 90% of the properties I use to lovely inflated properties on my strongly typed classes. I'll create custom property converters for the remaining 10% if I need them.
I'm sure others implement this differently, the models builder is extremely flexible. You'll play about with it for a while and come to a pattern you enjoy.
is working on a reply...