-
Notifications
You must be signed in to change notification settings - Fork 258
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split Bus App Lifetime Dependencies from CommandProcessor Instance Lifetime Dependencies #1628
Conversation
…al commandprocessor to be transient/scoped and have transient/scoped handlers or mappers
@preardon WIP I need to stop for a while, should have a little time later. ETA for something that shows if, and how this might work would be lunchtime 7 July |
PS Looking at the principal that as an implementation detail, we don't want to expose this as public just to allow us to get the singleton via DI, so using an old-skool double lock here instead. |
Just noticed that, I'll have a look as soon as I get s second, I will have to get my head around a few things (i.e. call back on a disposed object) but I'll see if I can have a look later tonight |
Let me finish up first, as I am not sure the Disposable CallContext will make the cut as it may not be thread proof. It will be in better shape tomorrow |
…e beyuond request
@preardon I am much happier with this starting point. We move the dependencies for the external bus into a singleton, as their lifetime is not per request.
I'll get the tests passing, but this is a branch, so we can both work on it. |
@preardon To understand it, just look at the CommandProcessor and ExternalBusServices files. They latter is what CommandProcessorServices turned into. |
@iancooper I'll have a look as soon as I get a minute |
Hey @iancooper , Sorry its taken so long but I've had a quick look, Just to make sure I'm on the same page, the Idea here is that we could set the Command Processor to have any service lifetime as the bits that need to be a singleton (External Bus Service are set once)? From what I can see this will work for Dependencies inside the Handler Factory, I am still having a think how this is going to work for what I had in my head around the EF Connection Provider for outbox (and some of the changes in the new Microsoft ASB Library, however I think I can keep them container if I add a Connection provider / Token Helper) Let me know what I can do to lend a hand here or if you would like to pair |
It's an idea that emerged for me during refactoring
Yes that is still outstanding
|
…red event service bus
I've been having a thing about this and I have an Idea, going to drive it out to see what the least about of invasive I can make it is. The Crux of it is that if we want the Outbox as a singleton (outside of scope) then it needs a Connection Provider that is out of Scope as well however if we want to provide the same connection as the Application, then it needs to be in scope as well, I think I've also got Token based Authentication mixed up in this in my head (as you need to get a token when the one you have expires) but I think I can break these into 2 separate problems, and Token Expiry is definitely something I can solve easily (will have to do this for ASB soon as well) I have the current 2 streams of though in my head
The thing that I'm not going to Love about this is that I will probably have to make a OutboxConnectionProvider type and then cast and check in each type of outbox Either way Will drive them out and see where I end up |
I think this is my thinking, but more really:
|
That is effectively what my PR ( #1635 ) does |
OK, we'll try to figure it out. I wanted to make sure I had the lifetimes right here, so that they could be set, and then look at how to merge the connection provider onto this. Trying to avoid too many moving parts now |
Yeah, it's getting to be a lot of change, I've added an extension method that registers the overriding connection provider so that you can set it to a separate lifetime to the rest of the outbox. The overriding connection provider should have the same lifetime as the command processor where as the default connection provider should be a singleton |
…ceCollection. Fix the slightly confusing to newbie raw ServiceCollection usage in a sample.
@preardon Going to merge and tag you in. I want a WebAPI + Ef Core sample, but I will create a separate branch and PR for that, so you can pursue the scope issue for outbox independent of that |
Move that which has app lifetime into a service. This is a WIP.
First pass, approach:
Create CommandProcessorService
Move all private methods there
Copy all private state there
Create singleton for service
Remove all private state from service that is scoped/transient
Fix any methods that need scoped/transient fields
Pass tests
Review CommandProcessor has any scoped/transient state
Review thread safety
Review split of methods - anything obviously in the home that breaks responsibility principles?