dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.63k stars 25.29k forks source link

Missing Lambda expression variable name #33676

Open rajanmishra18 opened 1 month ago

rajanmishra18 commented 1 month ago

Description

[Enter feedback here] Inside ConfigureService while implementing IMiddlewareFactory variable name is only _ while _container is being used.

services.AddTransient<IMiddlewareFactory>(_ => { return new SimpleInjectorMiddlewareFactory(_container); }); This should be replaced with

services.AddTransient<IMiddlewareFactory>(_container => { return new SimpleInjectorMiddlewareFactory(_container); });

Page URL

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/extensibility-third-party-container?view=aspnetcore-8.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/middleware/extensibility-third-party-container.md

Document ID

ea1db4c0-e8cc-98e8-a235-8c80e9a8f395

Article author

@Rick-Anderson

Rick-Anderson commented 1 month ago

@rajanmishra18 good catch. The sample should be updated to the minimal hosting model. Looks like that update was done or at least started here

@rajanmishra18 would you be interested in fixing the sample/doc?

@serpent5 do you know what happened in #25427 ?

rajanmishra18 commented 1 month ago

Hi Rick - I appreciate that you considered it. Yes, I would be glad to contribute to it.

Thanks & regards Rajan Mishra

On Mon, Sep 23, 2024 at 2:59 AM Rick Anderson @.***> wrote:

@rajanmishra18 https://github.com/rajanmishra18 good catch. The sample should be updated to the minimal hosting model. Looks like that update was done or at least started here https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/middleware/extensibility/samples/6.x

@rajanmishra18 https://github.com/rajanmishra18 would you be interested in fixing the sample/doc?

@serpent5 https://github.com/serpent5 do you know what happened in

25427 https://github.com/dotnet/AspNetCore.Docs/pull/25427 ?

— Reply to this email directly, view it on GitHub https://github.com/dotnet/AspNetCore.Docs/issues/33676#issuecomment-2366971532, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGAX7ZMG3EVSPR2JNKINJYTZX4ZCBAVCNFSM6AAAAABOUOEKKGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNRWHE3TCNJTGI . You are receiving this because you were mentioned.Message ID: @.***>

-- -- Thanks Rajan Mishra

serpent5 commented 1 month ago

In terms of the change suggested here...

Because the parameter passed into the AddTransient callback is IServiceProvider, and not Container, the example change won't compile. The reason it's named as _ in the example is because it's being discarded (it's unused). I think the example implies that _container is a field within Startup, and it's just being passed into SimpleInjectorMiddlewareFactory when it's created as transient service.

@Rick-Anderson It looks like #25427 was for "Factory-based middleware activation in ASP.NET Core", but this here is for "Middleware activation with a third-party container in ASP.NET Core". I didn't do anything with this topic, perhaps because it had fewer monthly views and was lower on the priority list.