Module settings in IOwinMiddlewareProvider.GetOwinMiddleWares

Topics: Writing modules
Jun 10 at 4:14 PM
Orchard 1.9.2

Hi,

I'm trying to access custom site settings in the IOwinMiddlewareProvider.GetOwinMiddleWares. I've tried injecting IOrchardServices in the constructor of The MiddleWare provider, but WorkContext is null at that moment.

this is throwing an exception:

var shareSettings = _services.WorkContext.CurrentSite.As<ShareBarSettingsPart>();

Is there another way of accessing the settings in the registration of Owin MiddleWare components.

Thnx,
Arjan
Jun 20 at 10:21 AM
I've dove deep into the core of Orchard and found that I can inject ISiteService. The code below returns the settings part.

var shareSettings = _siteService.GetSiteSettings().As<ShareBarSettingsPart>();
Jun 20 at 3:03 PM
Ported my solution to version 1.10.1 and got an Exception originating from Autofac.

Error: No scope with a Tag matching 'work' is visible from the scope in which the instance was requested. This generally indicates that a component registered as per-HTTP request is being requested by a SingleInstance() component (or a similar scenario.) Under the web integration always request dependencies from the DependencyResolver.Current or ILifetimeScopeProvider.RequestLifetime, never from the container itself.

Code:
public class OwinMiddlewares : IOwinMiddlewareProvider
{
    private readonly ISiteService _siteService;
    public ILogger Logger { get; set; }

    public OwinMiddlewares(
        ISiteService siteService
        )
    {
        _siteService = siteService;
        Logger = NullLogger.Instance;
    }

    public IEnumerable<OwinMiddlewareRegistration> GetOwinMiddlewares()
    {
        return new[]
        {
            new OwinMiddlewareRegistration
            {
                Priority = "9",
                Configure = app =>
                {
                    var wsFederationSettings = _siteService.GetSiteSettings().As<WsFederationSettingsPart>();
Any suggestions?

Regards,
Arjan