Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 29 19:03
    halter73 edited #355
  • Sep 29 18:19
    halter73 edited #355
  • Sep 29 18:17
    halter73 opened #355
  • Sep 29 13:04
    jeremydmiller opened #354
  • Sep 29 13:00
    jeremydmiller closed #348
  • Sep 29 13:00
    jeremydmiller commented #348
  • Sep 29 12:59
    jeremydmiller closed #347
  • Sep 29 12:59
    jeremydmiller commented #347
  • Sep 29 12:59
    jeremydmiller labeled #351
  • Sep 29 12:58
    jeremydmiller commented #351
  • Sep 29 12:56
    jeremydmiller commented #352
  • Sep 26 11:21
    prodigy1 closed #353
  • Sep 26 11:21
    prodigy1 commented #353
  • Sep 26 11:16
    prodigy1 edited #353
  • Sep 26 11:15
    prodigy1 opened #353
  • Sep 20 15:26
    andreas-valtech opened #352
  • Sep 13 20:04
    Fube opened #351
  • Aug 30 20:50
    dependabot[bot] labeled #350
  • Aug 30 20:50
    dependabot[bot] labeled #350
  • Aug 30 20:50

    dependabot[bot] on npm_and_yarn

    Bump vite from 2.7.2 to 2.9.15 … (compare)

Jeremy D. Miller
@jeremydmiller
You can inject IContainer as a constructor dependency and you'll always get the container that built the object
phinett
@phinett
Thanks. I found a way in the end to work this.

Have a different question now, i need to return all instances of a open generic type.

I am registering them like this:
Scan(a => { a.AssemblyContainingType<Content>(); a.ConnectImplementationsToTypesClosing(typeof(IEventHandler<>)); });

I now need to return all the IEventHandler's registered with a specific type.

Should this work:
_container.GetAllInstances<IEventHandler<T>>()

where T is a valid type.

phinett
@phinett
it's ok, it does work. I wasn't including the correct assembly in the Scan.
S
@skysgh

@jeremydmiller
Preamble:
It's not that the documentation is unclear...just that I'm thick, and unable to conceive of multiple routes to desired targets...or unable to give up easily on my first preconception as how to solve an issue...
Hence I'd just like to confirm:

In ASP.NET Core:

PreBuild Design Options
  • In the build phase, I can get my hands on a Configuration object...and register it in an IServiceCollection...but because we haven't Built() a ServiceProvider yet...
    • either have to re-fetch/build the same Configuration object in each
      Repository (since it can't be injected yet as IServiceProvider not yet built)
    • Or use a Singleton service to get back to the already obtained Configuration object.
    • So stop looking for another way and get on with things...
Post-Build design patterns
  • at startup, there's a Building phase where services can be registered, then a .Build() cutover phase at which point nothing else can be added to the menu of options.
    • Not even if I cast back from a generic IServiceProvider to a lamar specific IContainer.
    • So stop trying in that direction...

Still messing around -- but If I ever do get an AppDomain's based solution to loading Modules after startup, since the Build() event is long gone, and new service implements can no longer be added, AND although I can create a child container, that too is locked off from adding new services (raises exception), the options will be somewhere in the vicinity of:

  • Use a new Container, that is Module-Specific?

    • Can I teach it to extend/hand-off to the first container?
    • Or does this container have to be retaught everything, and its Singletons will actually be duplicates of the Singletons issued by the underlying core app?
  • Do you have an alternate suggestion/experience on how to think about achieving this objective?

    • I only ask, knowing that there will be more issues still: for example, late loaded Modules will contain API Controllers...that need registration as to their path...but that startup registration has long gone too.... :-(
Jeremy D. Miller
@jeremydmiller
@skysgh You want StructureMap-style child containers, which I very deliberately nuked out of Lamar because of the complexity. You might try Autofac instead. It's slow, but retains all that kind of flexibility you're looking for.
But if you're trying to make the AppDomains "unloadable" too, you'd want a separate container per AppDomain I'd think.
S
@skysgh
Thank you for the heads up. And advice. That said, even with " you'd want a separate container per AppDomain I'd think." It's still not going to be an easy walk in the park (due to paths, etc. all expecting to be baked before the app.Build() event).
I'll persevere and report findings if anything material comes up.
S
@skysgh
Just looked up performance. Wow you weren't kidding.
https://github.com/danielpalme/IocPerformance
Nicholas Budd
@anaximander23
so this might be a weird one, but I'm having some trouble with open generics
basically I'm doing an assembly scan with scan.ConnectImplementationsToTypesClosing(typeof(InterfaceA<>));
but somewhere I have an implementation that is ConcreteType<TValue> : InterfaceA<InterfaceB<TValue>>
so, in the application I try to do
var openType = typeof(InterfaceA<>);
...
var subType = typeof(InterfaceB<SomeType>);
var target = openType.MakeGeneric(subType);

var resolved = _container.GetService(target);
Nicholas Budd
@anaximander23
the result is that the call to GetService() throws an ArgumentOutOfRangeException with the message "MyApp.ConcreteType<<InterfaceB<SomeType>>> cannot be cast to InterfaceA<<InterfaceB<SomeType>>> (Parameter 'implementationType')'"
which is weird because that type absolutely does implement that interface
Jeremy D. Miller
@jeremydmiller
You might double check that, because if Lamar is throwing that, it's because the IsAssignableFrom() call returned false. My only real advice is "don't do that kind of thing"
How'd you get into that scenario? Was this from MediatR usage, or something else?
Nicholas Budd
@anaximander23
something else, although MediatR is in this app
basically I've got a lot of methods in the domain assembly that return a Result<T> type
and in the API layer the plan is to map these to HTTP responses
Jeremy D. Miller
@jeremydmiller
So, homegrown MediatR like thing?
Nicholas Budd
@anaximander23
so you've got IResultMapper<T> that has a Map<TResult>(TResult result) method that returns your HTTP content
not exactly like a MediatR thing; it's more that it's using this Result type as a functional-programming-style Maybe thing
Jeremy D. Miller
@jeremydmiller
Gotcha.
Nicholas Budd
@anaximander23
it's like Task<T> but instead of being to do with async it's to allow it to signal failure and things without throwing exceptions
you'd return a DuplicateKeyResult, or DomainRuleViolationResult, or whatever
so the idea is that you can have mappers that turn those into HTTP
so you'd have DuplicateKeyResultMapper<T> : IResultMapper<DuplicateKeyResult<T>> where the implementation returns a 409 Conflict
etc
so, the actual mapper component is being passed the result and needs to find the mapper for that kind of result
very similar mechanism to MediatR's resolving handlers, really
but different purpose
Jeremy D. Miller
@jeremydmiller
I understand. What you don't want to hear though is that folks that try to do exactly that kind of thing with a lot of open generics types and take advantage of co/contra variance for reuse tend to run into the exact kind of problem you are here.
Nicholas Budd
@anaximander23
yeah, I realise that, and I can see how it'd be weird and complex
it's actually working for some of the results and mappers
...all the ones where they're specific enough that the results and/or mappers don't have generic type args
so yeah, the problem is clearly in the number of layers of generic
Jeremy D. Miller
@jeremydmiller
One way or another, you most likely need to adjust co/contra variance somewhere along the way
Nicholas Budd
@anaximander23
what's frustrating is that I've done something like this before and I remember it being a bit fiddly but I did get it working and I can't remember how lol
previous company; don't have access to that source code any more
Michael Fyffe
@TraGicCode

Anyone know how i can get more information from Lamar on why this error is happening? These are .net framework targeted csprojs ( and the root application is .net core )

Assemblies that failed in the call to Assembly.GetExportedTypes()

  • XXXXX.Core, Version=67.2017.9.1, Culture=neutral, PublicKeyToken=null
Jeremy D. Miller
@jeremydmiller
You've got a missing, declared dependency of that assembly. In the obj file, there's a massive JSON file that explains the whole dependency chain. That might help. Also though, take a look at this: https://jasperfx.github.io/lamar/guide/ioc/diagnostics/type-scanning.html
Michael Fyffe
@TraGicCode

Hey @jeremydmiller ,

This is a .net framework csproj that is having issues. Will it still have the json file? If so i assume i have to make sure every assembly is being referenced?

Jeremy D. Miller
@jeremydmiller
Ah, in that case, go for the fusion log viewer on the box that failure happened. That should point out the missing assembly. Once you identify that, you can zero in on maybe adding a missing Nuget.
Michael Fyffe
@TraGicCode
I can give that a shot! hopefully it wont be to painful
As a side note, i did run the upgrade-assist tool partiall on the project and the error went away. I'm sure there are a bunch of stuff broken though from the upgrade
Jeremy D. Miller
@jeremydmiller
A Venn diagram of good days and days you need to use the fusion log viewer is just two circles
:thumbsup:
Michael Fyffe
@TraGicCode
all i remember is looking at fusion logs is a PITA
Jeremy D. Miller
@jeremydmiller
The Assembly.GetExportedTypes() that the assembly scanning uses is brittle