amantinband / clean-architecture

The ultimate clean architecture template for .NET applications 💪
MIT License
1.4k stars 221 forks source link

Using options pattern in a different way #7

Closed amirhessampourhossein closed 7 months ago

amirhessampourhossein commented 7 months ago

Currently, this is how your JwtSettings is configured 👇

var jwtSettings = new JwtSettings();
configuration.Bind(JwtSettings.Section, jwtSettings);
services.AddSingleton(Options.Create(jwtSettings));

What's your opinion about the approach below 👇

services.AddOptions<JwtSettings>().BindConfiguration(JwtSettings.Section);

we could also add validation in two different ways :

amantinband commented 7 months ago

Generally I go with what you suggested, but over here we need to both register the settings as singleton and use it a few lines later: image

Regarding validation, not sure I want to add this to the template, but let me think about it. Keeping the issue open for now

amirhessampourhossein commented 7 months ago

What about separating the second part and putting it in another class that implements IConfigureOptions<JwtBearerOptions> ?

amantinband commented 7 months ago

Yeah that's a good option as well. Feel free to create a PR for this if you'd like :)

amantinband commented 7 months ago

Thanks Amir! 🫶