Skip to content
This repository was archived by the owner on Nov 7, 2018. It is now read-only.
This repository was archived by the owner on Nov 7, 2018. It is now read-only.

Options 2.0 changes (named/validation/caching) for Auth 2.0 #161

Closed
@HaoK

Description

@HaoK

See if there's a way to reintroduce named options in a nicer way, such that we can consume it the same way today via IOptions/ISnapshotOptions.Value, where a new IOptionsNameSelector service would be the customization point where name(aka tenant) can be selected.

High level usage:

    // Add some kind of NamedInstance string property to IConfigure<TOptions>

    // Configure
    services.Configure<MyOptions>("Tenant1", o => o.Connection = "conn1");
    services.Configure<MyOptions>("Tenant2", o => o.Connection = "conn2");
    services.AddScoped<IOptionsNameSelector, MyTenantSelector>();
    
    public MyTenantSelector : IOptionsNameSelector {
        public MyTenantSelector(IHttpContextAccessor accessor);
        public string ResolveOptionsName() {
             return GetTenantNameFromRequest(accessor);
        }
    }

    public Controller(IOptions<MyOptions> options) {
       var tenantAwareOptions = options.Value;
    }

    public Controller(ISnapshotOptions<MyOptions> options) {
       var tenantAwareOptions = options.Value;
    }

The options implementations would use the IOptionsNameSelector and NamedInstance to return the appropriate options instance

Hopefully we can do this simply by enhancing the existing implementations of the current interfaces... But its possible we might need to introduce INamedOptions<MyOptions>.

This would dovetail nicely with the auth changes that could take advantage of this feature via named auth scheme options

cc @divega @glennc

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions