Open neman opened 6 years ago
Yes but please don't use MVC for the example. Stick to bare bone ASP.NET Core. We need to minimize the number of concepts that people need to know in any given examples.
Yes, of course. This was just an example from the head. I will use middlewares, but than I cant inject services. I will retrieve them directly from the container.
Middleware can inject services in the constructor or in the Invoke method. https://github.com/aspnet/HttpAbstractions/blob/07d115400e4f8c7a66ba239f230805f03a14ee3d/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/UseMiddlewareExtensions.cs#L89-L110
Nice.
@Tratcher https://github.com/dodyg/practical-aspnetcore/blob/master/projects/middleware-9/src/Program.cs shows construction injection service. It should be modified to show injection at the Invoke method as well.
@Tratcher I know I can inject service in custom middleware Invoke method (I did it many times). I was pointing out to app.Run or app.Use. If I’m going to use bare bone ASP.NET Core instead of MVC, than I should try to avoid building custom middleware also. If it's possible that would be great.
I modified middleware-9
to demonstrate injection at Invoke
as well (https://github.com/dodyg/practical-aspnetcore/commit/e852ef3bd385ab1a0b885ef2e39d12bb2b9bc875)
In the DI section I found your comment
Note: example 2 is forthcoming. The inspiration has not arrived yet.
Is this good enough for an example? I can make an example and PR something like this: