Skip to content
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

Integration Testing Mode for easy runtime swapping of services #342

Open
jeremydmiller opened this issue Jun 7, 2022 · 3 comments
Open

Comments

@jeremydmiller
Copy link
Member

// cc @kkorotky

Request from one of our teams. Lamar is not nearly as flexible as StructureMap at runtime. This was a conscious decision on my part to improve performance and keep folks from shooting themselves in the foot and running to me for help when they did. The downside is that is that Lamar isn't that great for swapping in test services per test. You can use Injectable upfront, but that requires knowing which services will be swapped out ahead of time.

What if we had a mode where the container allowed for easier swapping at will, and reset all registrations back to the original registration with a single method call in a test fixture clean up? More investigation necessary. I'm thinking that in this mode Lamar uses QuickBuild() for everything so it's easier to swap things in and out.

@jbogard
Copy link

jbogard commented Feb 8, 2023

To piggyback, we have a common pattern in StructureMap:

  1. Create "blueprint" root container
  2. Create a nested container based on the root container
  3. Use Configure to swap out a dependency for a mokc
  4. Dispose the nested container

For .NET Core/5/6, we wind up using the WebApplicationFixture and OverrideServices stuff, but it forces us to rebuild the entire container every time. We do have well-known stubs injected into the container to swap out, like user sessions etc. But to do arbitrary mocking we have to rebuild the whole container.

@jbogard
Copy link

jbogard commented Feb 10, 2023

Was pointed to this: https://github.com/rsivanov/Rsi.DependencyInjection by @rsivanov, gonna try that out.

@jbogard
Copy link

jbogard commented Feb 13, 2023

Just to follow up, the strategy in the repo above doesn't work because it's trying to wrap the ServiceDescriptor instances in the service collection. However, Lamar populates those values with Lamar-specific things so the wrapped values are all wrong. Back to the drawing board.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants