Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AddedAddCouchContext overloads that supply the service provider to the caller.#210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
nefarius wants to merge3 commits intomatteobortolazzo:master
base:master
Choose a base branch
Loading
fromnefarius:nefarius/feature/di-overload

Conversation

nefarius
Copy link
Contributor

AddedAddCouchContext overloads that supply the service provider to the caller. This allows for code like:

builder.Services.Configure<DatabaseSettings>(builder.Configuration.GetSection(nameof(DatabaseSettings)));builder.Services.AddCouchContext<DocumentsContext>(sp=>{DatabaseSettingssettings=sp.GetRequiredService<IOptions<DatabaseSettings>>().Value;CouchOptionsBuilder<DocumentsContext>b=new();b.UseEndpoint(settings.ServerUrl);b.UseBasicAuthentication(settings.Username,settings.Password);returnb;});

So everything stays "within" DI and is consumed by it too.

@matteobortolazzo
Copy link
Owner

Hello! First of all, thanks for the PR!

However, I don't fully understand the goal. In the case of the example, why use DI in the first place when you can do it without? I implemented it like Entity Framework.

varsettings=builder.Configuration.GetSection(nameof(DatabaseSettings)).GetValue<DatabaseSettings>();builder.Services.AddCouchContext<DocumentsContext>(builder=>builder.UseEndpoint(settings.ServerUrl);.UseBasicAuthentication(settings.Username,settings.Password));

Maybe a valid case is a service that resolves the server name or credentials. But then I can be easier to inject that in the context and use it inOnConfiguring probably.

@nefarius
Copy link
ContributorAuthor

nefarius commentedJul 12, 2025
edited
Loading

Yes, it is not the zenith of clever code, I added it because it adheres to how other common DI fluent APIs are designed, like AddHttpClient and so on. My Web app has many more configuration parameters than just the DB so since I need the same info all over the place registering and consuming one IOptions is "cleaner". In my opinion ofc 😜

Ultimately I wanted to eliminate having to pass around configuration variables all across my app entry and keepeverything within IoC paradigms, if that makes sense. It's probably very nitpicky but hey, welcome to my world 😁

@matteobortolazzo
Copy link
Owner

matteobortolazzo commentedJul 14, 2025
edited
Loading

Got it. Still not sure about 100% to add it to the library, or at least it should be:

Action<IServiceProvider,CouchOptionsBuilder<TContext>>

The builder constructor was not meant to be public tbh.

BTW I see it's 1+ year I don't update this library. Maybe I take a break from my stuff and work on it this week.

I can release a 3.7 version with a few things in from issues and PRs, then check what I can do aboutSystem.Text.Json with a v4

@nefarius
Copy link
ContributorAuthor

The builder constructor was not meant to be public tbh.

Good call! Will modify it accordingly.

BTW I see it's 1+ year I don't update this library. Maybe I take a break from my stuff and work on it this week.

Do you need help with that? I am currently actively back in a project making heavy use of this library so I am still finding things I wanna see fixed 😉

@matteobortolazzo
Copy link
Owner

That would be great!

I can investigate System.Text.Json since it's now commonly used. And I can move to net8 finally

@nefarius
Copy link
ContributorAuthor

IDK how you prefer to communicate or what your availability is like but be my gueston my Discord if you want the most direct line to me for communication 🫡

@matteobortolazzo
Copy link
Owner

Cool, makes sense, joined

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@nefarius@matteobortolazzo

[8]ページ先頭

©2009-2025 Movatter.jp