question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UseMiddlewareFromWindsor cannot pass arguments into the middleware

See original GitHub issue

This issue is related to https://github.com/fir3pho3nixx/Windsor/tree/aspnet-core-windsor-final branch

UseMiddlewareFromWindsor extension method (https://github.com/fir3pho3nixx/Windsor/blob/fa3617bf19e4f53430e018d543ababa00388e005/src/Castle.Facilities.AspNetCore/WindsorRegistrationExtensions.cs#L90) cannot pass arguments into the middleware.

I had to come up with a modified version with a new parameter argumentsAsAnonymousType:

public static void UseMiddlewareFromWindsor<T>(this IApplicationBuilder app, IWindsorContainer container, object argumentsAsAnonymousType)
	where T : class, IMiddleware
{
	container.Register(Component.For<T>());
	app.Use(async (context, next) =>
	{
		var resolve = container.Resolve<T>(argumentsAsAnonymousType);
		try
		{
			await resolve.InvokeAsync(context, async (ctx) => await next());
		}
		finally
		{
			container.Release(resolve);
		}
	});
}

Example of usage:

app.UseMiddlewareFromWindsor<TransactionScopeUnitOfWorkMiddleware>(_windsorContainer, new { isolationLevel = IsolationLevel.ReadCommitted });

In this example it passes read committed isolation level into the TransactionScopeUnitOfWorkMiddleware.

Should I create a pull request? Or do you think this can be added by you? Cheers.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:26 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Jul 2, 2018

Awesome. We did not notice any memory spikes either. Closing for now. Please raise new issues when you find them.

1reaction
ghostcommented, Jul 1, 2018

@xhafan Can you please take a look at the latest cut? You also should not need to cross wire anything.

I am going to drop this into production tomorrow. If I find anything I will let you know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing arguments to Middleware class
1 Answer. It isn't possible to pass objects to the factory-activated middleware with UseMiddleware,If you do want to pass argumentss to your  ......
Read more >
Passing Parameters To Middleware In ASP.NET Core 2.0
How do you pass parameters to middleware during its setup in ASP.NET Core? Solution. In an empty project add a POCO class to...
Read more >
Passing arguments to Middleware class : r/dotnet
I have a piece of middleware I'm trying to build that will check if a user has a particular key and if they...
Read more >
How to pass second parameter to middleware in Route
I guess, the problem here is with the "Auth::user" which Laravel obviously cannot translate, but I have no clue how to pass that...
Read more >
Passing Arguments
Just like a REST API, it's common to pass arguments to an endpoint in a GraphQL API. By defining the arguments in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found