Copied to clipboard

Flag this post as spam?

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


  • Josefine 2 posts 73 karma points
    Mar 16, 2019 @ 11:10
    Josefine
    1

    OnApplicationStarted Umbraco 8

    How do I register bundle config on application started in Umbraco 8?

    Before in Umbraco 7 I used this:

    public class MvcApplication : Umbraco.Web.UmbracoApplication
    {
        protected override void OnApplicationStarted(object sender, EventArgs e)
        {
            base.OnApplicationStarted(sender, e);
    
            AreaRegistration.RegisterAllAreas();
            BundleConfig.RegisterBundles(BundleTable.Bundles);
    
        }
    }
    
    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new StyleBundle("~/bundles/site.css").Include(
            "~/css/style.css"
            ));
        }
    }
    

    Thanks,

    Josefine

  • Sebastiaan Janssen 4876 posts 14511 karma points MVP admin hq
    Mar 18, 2019 @ 07:23
    Sebastiaan Janssen
    5

    While I'm not too familiar with Bundles, have a look at the documentation for attaching to events, that happens during the Initialization of Umbraco so hopefully works for you:

    https://our.umbraco.com/documentation/Implementation/Composing/#example---creating-a-component-to-listen-for-contentservicesaving-events

    Example code could look a bit like:

    using System.Web.Mvc;
    using Umbraco.Core;
    using Umbraco.Core.Composing;
    
    namespace MyProject.Components
    {
        [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
        public class MyComposer : IUserComposer
        {
            public void Compose(Composition composition)
            {
                composition.Components().Append<MyComponent>();
            }
        }
    
        public class MyComponent : IComponent
        {
            public MyComponent()
            {
    
            }
    
            public void Initialize()
            {
                AreaRegistration.RegisterAllAreas();
                BundleConfig.RegisterBundles(BundleTable.Bundles);
            }
    
            public class BundleConfig
            {
                public static void RegisterBundles(BundleCollection bundles)
                {
                    bundles.Add(new StyleBundle("~/bundles/site.css").Include(
                        "~/css/style.css"
                    ));
                }
            }
    
            public void Terminate()
            {
            }
        }
    }
    
  • Josefine 2 posts 73 karma points
    Mar 24, 2019 @ 10:37
    Josefine
    0

    Thanks a lot! :)

    Regards Josefine

Please Sign in or register to post replies

Write your reply to:

Draft