Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 12 00:39
    jeremydmiller commented #348
  • Aug 02 15:33
    darman96 commented #224
  • Jul 25 01:03
    PrisonerZERO closed #349
  • Jul 25 00:45
    PrisonerZERO edited #349
  • Jul 25 00:42
    PrisonerZERO commented #349
  • Jul 25 00:41
    PrisonerZERO commented #349
  • Jul 25 00:40
    PrisonerZERO commented #349
  • Jul 24 20:43
    PrisonerZERO commented #349
  • Jul 24 20:42
    PrisonerZERO commented #349
  • Jul 24 20:41
    PrisonerZERO commented #349
  • Jul 24 20:40
    PrisonerZERO commented #349
  • Jul 24 20:39
    PrisonerZERO commented #349
  • Jul 24 20:39
    PrisonerZERO commented #349
  • Jul 24 20:13
    PrisonerZERO edited #349
  • Jul 24 20:10
    PrisonerZERO edited #349
  • Jul 24 20:09
    PrisonerZERO edited #349
  • Jul 24 20:09
    PrisonerZERO edited #349
  • Jul 24 20:06
    PrisonerZERO edited #349
  • Jul 24 20:03
    PrisonerZERO edited #349
  • Jul 24 17:01
    PrisonerZERO edited #349
Nicholas Budd
@anaximander23
and because ServiceRegistry implements IEnumerable<ServiceDescriptor> theoretically you could just do testServices.RemoveAll(new MyRegistry());
cool, that should cover it
Jeremy D. Miller
@jeremydmiller

and because ServiceRegistry implements IEnumerable<ServiceDescriptor> theoretically you could just do testServices.RemoveAll(new MyRegistry());

Yeah, no, that's probably not going to work. You have to do that against the main ServiceCollection for the app. It's not magic.

Nicholas Budd
@anaximander23
oh, is that not the same one that gets passed to the ConfigureTestServices method?
or does it create a child container or something?
image.png
Jeremy D. Miller
@jeremydmiller
That should be, but you can't do the remove all business from a Lamar ServiceRegistry because that's purely additive. That's what I mean
Nicholas Budd
@anaximander23
I was just looking at the MS docs and they say you can do this
so I figured it'd be an extension of that same logic
I mean, I don't really like the idea of removing and then adding
Jeremy D. Miller
@jeremydmiller
Yes, but they're not accounting for anyone using native IoC container registrations.

I mean, I don't really like the idea of removing and then adding

Not really a big deal IMO

Nicholas Budd
@anaximander23
I'd rather have some logic that does an "if test register this, else register that"
just feels cleaner
yeah, not a huge deal, but it feels like the more tidy approach
Jeremy D. Miller
@jeremydmiller
You can do that too, but many folks wouldn't want that embedded directly in their app
Nicholas Budd
@anaximander23
yeah, that's fair
it's mostly that it means in order to test your app you need to know a little bit more about its internal implementation in order to know what to remove from the container
if you're just adding stuff then it's more just that you know the things it depends on, which is kinda like part of the externally-visible contract for it
rather than knowing how those things are implemented so you know what to remove

Yes, but they're not accounting for anyone using native IoC container registrations.

so if you did what's in that screenshot in an app that uses Lamar, it wouldn't work?

oh, wait
I see what you mean
right
you'd need some logic to run through a ServiceRegistry and match each thing it does against something in a container and remove them based on that
Jeremy D. Miller
@jeremydmiller
I think you need to just experiment a little bit in the code. This might not be a big deal at all
Nicholas Budd
@anaximander23
it'd be like... I dunno,
var addedByRegistry = new MyServiceRegistry().Select(x => x.ServiceType);
var toRemove = services.Where(x => addedByRegistry.Contains(x.ServiceType));

services.RemoveAll(toRemove);
or something to that effect
Jeremy D. Miller
@jeremydmiller
You know it doesn't really hurt to just add overrides at the end. You don't have to remove the old registrations if they're not used
Last one wins in asp net core world
Nicholas Budd
@anaximander23
ah, true
plus then I guess you could add a test that runs the verify method and it'd be checking everything because you didn't remove anything
although the overrides might hide stuff I suppose
Robert M Jordan
@robertmjordan_twitter

Hi there...
I'm having some issues with Constructor Selection & the ability to pass DbContextOptions.

When able...
Could you take a look at my StackOverflow Question & give me some advice?

Thank you

Jeremy D. Miller
@jeremydmiller
“1. Lamar isn't respecting Constructor Selection” — I’m gonna say that I’m very dubious about that. My strong advice is to actually stop trying to accomplish this through Lamar gymnastics and just use conditional registration in your bootstrapping. Remember that you can check the IHostEnvironment.EnvironmentName during bootstrapping and use if/then code for the registrations. That or in your test harness, just override the service registrations.
This code:
For<DbContext>().Use<WorkflowComponentDbContext>();
Only applies to registrations of DbContext. So only if you’re injecting DbContext directly. And when you do that, it would be using the WorkflowComponentDbContext default constructor.
This registration is completely separate from the one above and will not have any impact on the earlier registration:
ForConcreteType<WorkflowComponentDbContext>().Configure.Ctor<DbContextOptions<WorkflowComponentDbContext>>().Is(optionsBuilder.Options);
Remember that the Lamar registration is identified by the implementation type & the concrete type. There’s no magic crossover from the second registration to the first registration.
Robert M Jordan
@robertmjordan_twitter

Hi Jeremy,
Thanks for the help...especially since it's Sunday.

“Lamar isn't respecting Constructor Selection”
What I mean is...it isn't passing-through the DbContextOptions I built...because the one passed into the constructor are empty.

(see images at the bottom of the my StackOverflow Question)

"There’s no magic crossover between the 1st & 2nd registrations"
Cool. That makes sense. This explains why in "Attempt One" of the StackOverflow Question both of the constructors get called.

That said...
I've removed the default constructor:
[DefaultConstructor] public WorkflowComponentDbContext() { }

And I replaced original registration to contain only this:

For<DbContext>().Use<WorkflowComponentDbContext>().SelectConstructor(() => new WorkflowComponentDbContext(optionsBuilder.Options));

Yet, I'm still receiving an empty set of DbContextOptions...even though the passed-in reference is populated.

(this is displayed at the bottom of the my StackOverflow Question)

Any thoughts there?
(you can answer on Monday if you like)

Jeremy D. Miller
@jeremydmiller
Are you registering this with AddDbContext()?
And another idea that’s a non-Lamar turn, are you using a shared database server for development? Is that why you use the developer name for the database name? If that’s the case, one way to simplify that is to use Docker containers for the local dev database. That way there’s no difference in connection string and less hassle overall.
Robert M Jordan
@robertmjordan_twitter

Hi Jeremy,
I haven't even gotten to the point of pushing this out into any environment yet. I'm running this locally...across project examples...within the same Visual Studio Solution (for initial testing purposes).

CONSOLE APP Project
I create & pass-in a set of DbContextOptions with the (local) connection string (to test Db-Integration).

UNIT TEST Project
I create & pass-in the UseInMemoryDatabase option.

"How I am registering"
I am using the Bootstrapping a Container by passing-in a ServiceRegistry...and then I am using the Container to create an instance.

I haven't even tried using this in a Web Project (yet).

Anyway...thanks for the help. Stew on it for a bit (I will be too)

If you want...
I can create a "slim" version of this thing tomorrow & send it.

Robert M Jordan
@robertmjordan_twitter
FYI...
I've updated my StackOverflow Question with updates (at the bottom)
Jeremy D. Miller
@jeremydmiller
I think I'd just recommend that your use AddDbContext<T>() against IServiceCollection like you see in most samples. You can do a conditional registration thing against the IHostEnvironment to switch to the in memory database if you're in testing mode or development mode. That's the idiomatic way to do this, and what you'll find other folks online
Bill Robertson
@billrob
Are there any notes on changes from v7 to v8?
Jeremy D. Miller
@jeremydmiller
Not much. This: https://github.com/JasperFx/lamar/issues?q=is%3Aclosed+milestone%3A%22Lamar+8.0%22. Lamar has been very stable for several years. There's been a couple additive changes, but mostly the big version bumps have been around what versions of .NET they support or eliminating/adding WebHostBuilder/HostBuilder.
Bill Robertson
@billrob
Perfect, thanks