GithubHelp home page GithubHelp logo

Comments (8)

divega avatar divega commented on July 26, 2024

Should we also have the empty overload of UseXyz() to pull options from DI without touching them?

from options.

HaoK avatar HaoK commented on July 26, 2024

The base class doesn't work well, I tried that option and it fails miserably with AuthenticationOptions since it gets in the way of the base options classes. We probably have to use a wrapper like @pinpointTownes suggested that's only used in the UseXyz overloads (alternative implementation of IOptions basically)

I think UseXyz() should exist where appropriate, its definitely not always appropriate for middleware that requires configuration keys etc

from options.

kevinchalet avatar kevinchalet commented on July 26, 2024

Should we also have the empty overload of UseXyz() to pull options from DI without touching them?

@divega that's more or less the pattern I recently suggested to @HaoK (except that my approach was still compatible with named options): https://github.com/PinpointTownes/Security/commit/26b511f3d294f4b9545e1fbc57e4ef5226672118#commitcomment-12263892

We probably have to use a wrapper like @pinpointTownes suggested that's only used in the UseXyz overloads (alternative implementation of IOptions basically)

Ideally, you could even use it everywhere you have to deal with IOptions<TOptions> (like MemoryCache, whose constructor requires IOptions<MemoryCacheOptions>):

public static MemoryCache Create(MemoryCacheOptions options) {
    return new MemoryCache(new Options<MemoryCacheOptions>(options));
}

var cache = MemoryCache.Create(new MemoryCacheOptions {
    CompactOnMemoryPressure = false
});

from options.

HaoK avatar HaoK commented on July 26, 2024

If we go the wrapper route, we should probably just enhance the existing OptionsManager implementation of IOptions to support this usage rather than a different duplicate class with a very similar name and purpose

from options.

divega avatar divega commented on July 26, 2024

Interesting. I also suggested a wrapper when we met. My variation had a static method that would wrap any T instance into an IOptions<T>. Think Options.Create(new XyzOptions { Whatever = x }). The main push back was discoverability.

from options.

divega avatar divega commented on July 26, 2024

BTW, if the base class is just for convenience it would be OK for options that need their own base classes to implement IOptions<T> on their own, correct? I.e. it should be OK to have the base class and just not use it always.

from options.

HaoK avatar HaoK commented on July 26, 2024

from options.

HaoK avatar HaoK commented on July 26, 2024

Looks like we've settled on not using IOptions for middleware options in general

from options.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.