Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4367 posts 9473 karma points MVP 2x admin c-trib
    Sep 10, 2019 @ 11:46
    Ismail Mayat
    0

    Inject IUmbracoContextFactory into OwinStartup class

    So I have a class that inherits from UmbracoDefaultOwinStartup its in an inherited site. Its making use of content service to get some config stuff.

    Is it possible to inject in IUmbracoContextFactory then I can use the cache to do the same thing or is this to early in the pipleine?

    Ismail

  • Rasmus John Pedersen 11 posts 418 karma points hq c-trib
    Sep 10, 2019 @ 12:01
    Rasmus John Pedersen
    0

    Hi Ismail

    Not sure if you've seen my reply on slack, but instead of overwriting UmbracoDefaultOwinStartup you can create a component and listen to the UmbracoDefaultOwinStartup.MiddlewareConfigured event. This event is fired when Umbraco is done configuring Owin

    using Owin;
    using Umbraco.Core.Composing;
    using Umbraco.Web;
    ​
    namespace Website
    {
        public class MyComposer : ComponentComposer<MyComponent>, IUserComposer
        {
        }
    ​
        public class MyComponent : IComponent
        {
            public MyComponent()
            {
                // inject dependencies in the constructor
            }
    ​
            public void Initialize()
            {
                UmbracoDefaultOwinStartup.MiddlewareConfigured += (_, e) => ConfigureMiddleware(e.AppBuilder);
            }
    ​
            private void ConfigureMiddleware(IAppBuilder app)
            {
                // this is called when Umbraco is done configuring the Owin middleware
            }
    ​
            public void Terminate()
            {
            }
        }
    }
    
  • Ismail Mayat 4367 posts 9473 karma points MVP 2x admin c-trib
    Sep 10, 2019 @ 12:23
    Ismail Mayat
    0

    Hmm, but i need todo this:

            protected override void ConfigureUmbracoAuthentication(IAppBuilder app)
        {
            base.ConfigureUmbracoAuthentication(app);
            ConfigureAuth(app);
        }
    

    what maybe i cannot do in the composer?

  • Rasmus John Pedersen 11 posts 418 karma points hq c-trib
    Sep 10, 2019 @ 12:30
    Rasmus John Pedersen
    0

    It's AFAIK not possible to inject stuff into the OwinStartup class But looking at the UmbracoDefaultOwinStartup, ConfigureUmbracoAuthentication() is called right before the event is triggered https://github.com/umbraco/Umbraco-CMS/blob/8f32fce7818a556d4879e66851dbe91221c63fdc/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs#L69 (the FinalizeMiddlewareConfiguration triggers the event)

    So you should be able to run you're auth configuration in the ConfigureMiddleware method in the Component example shown above

  • Ismail Mayat 4367 posts 9473 karma points MVP 2x admin c-trib
    Sep 10, 2019 @ 12:47
    Ismail Mayat
    0

    Awesomes will give that a whirl, thanks for you help.

Please Sign in or register to post replies

Write your reply to:

Draft