Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kevin Jump 2309 posts 14673 karma points MVP 7x c-trib
    Jan 19, 2017 @ 11:09
    Kevin Jump
    0

    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 ?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 19, 2017 @ 11:15
    Jeroen Breuer
    101

    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

  • Dan Lister 416 posts 1974 karma points c-trib
    Jan 19, 2017 @ 11:15
    Dan Lister
    1

    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.

  • Kevin Jump 2309 posts 14673 karma points MVP 7x c-trib
    Jan 19, 2017 @ 11:30
    Kevin Jump
    0

    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.

  • Bruce 17 posts 82 karma points
    Jan 20, 2017 @ 08:59
    Bruce
    1

    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:

    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
    <add key="Umbraco.ModelsBuilder.ModelsMode" value="Nothing" />
    <add key="Umbraco.ModelsBuilder.EnableApi" value="true" />
    <add key="Umbraco.ModelsBuilder.ModelsNamespace" value="App.PublishedContentModels" />
    

    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.

Please Sign in or register to post replies

Write your reply to:

Draft