Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 05 10:54
    ChristianSteu opened #282
  • Apr 21 00:25
    sid5 edited #281
  • Apr 21 00:24
    sid5 opened #281
  • Apr 13 11:14

    jeremydmiller on master

    Remove ignored files (compare)

  • Apr 13 11:14
    jeremydmiller closed #278
  • Mar 25 09:05
    JulianKlauser opened #280
  • Mar 19 23:06
    Cybrosys commented #252
  • Mar 19 23:05
    Cybrosys edited #279
  • Mar 19 22:46
    Cybrosys edited #279
  • Mar 19 17:31
    Cybrosys commented #279
  • Mar 19 17:31
    Cybrosys commented #279
  • Mar 19 17:31
    Cybrosys edited #279
  • Mar 19 17:20
    Cybrosys commented #279
  • Mar 19 17:20
    Cybrosys commented #279
  • Mar 19 16:50
    Cybrosys commented #279
  • Mar 19 16:48
    Cybrosys commented #279
  • Mar 19 16:46
    Cybrosys reopened #279
  • Mar 19 16:21
    Cybrosys commented #279
  • Mar 19 16:21
    Cybrosys closed #279
  • Mar 19 16:01
    Cybrosys edited #279
Bryan Boettcher
@bryanboettcher
i have an interface, IGetOne<TKey, TOutput> that i want to implement via generics forwarding to a FetchOne<TKey, TOutput>

i can do that perfectly with:

registry.For(typeof(IGetOne<,>)).Use(typeof(FetchOne<,>));

but, the problem comes now with an optional Monad-type we have, to try and satisfy IGetOne<TKey, Monad<TOutput>>
the actual code is:
public sealed class ForwardingRepository<TKey, TOut> :
        IRetrieve<TKey, TOut>
        , IRetrieve<TKey, Option<TOut>>
    {
        private readonly IRetrieveMany<TKey, TOut> _baseRepository;

        public ForwardingRepository(IRetrieveMany<TKey, TOut> baseRepository) =>
            _baseRepository = baseRepository;

        async Task<TOut> IRetrieve<TKey, TOut>.RetrieveAsync(TKey key, Guid transaction) =>
            await _baseRepository.RetrieveManyAsync(key, transaction).SingleAsync();

        async Task<Option<TOut>> IRetrieve<TKey, Option<TOut>>.RetrieveAsync(TKey key, Guid transaction) =>
            Option.FromNullable(await _baseRepository.RetrieveManyAsync(key, transaction).FirstOrDefaultAsync());
    }
the problem i'm running into is trying to GetInstance<MyKey, Option<MyOutput>> is only pinging on the first interface, so it's forwarding "Option<MyOutput>" to the second injected interface
so, halp. wat do
Bryan Boettcher
@bryanboettcher
in addition, i just upgraded to Lamar 5.0.x, and now my TypeSet doesn't contain .FindTypes() anymore
Jeremy D. Miller
@jeremydmiller
@bryanboettcher So what isn’t working up above? And check your type scanning diagnostics to find out what’s going on in your dependency tree with the FindTypes().
Bryan Boettcher
@bryanboettcher
hi Jeremy :)
i mean i get the compilation error "TypeSet does not contain a definition for FindTypes" -- willing to write this off as resharper being goofy if you say those APIs didn't change between 4.7.x and 5.0.x
Jeremy D. Miller
@jeremydmiller
That’s an assembly mismatch. Might try a hard git clean -xfd, then recompile after switching up dependencies
Bryan Boettcher
@bryanboettcher
as for my earlier question, it's more a question of using the For(typeof()) mechanics
i have a wrapper class (Option<T> -- my monad) that i am trying to get lamar to recognize and strip-out when it's doing the T forwarding
Jeremy D. Miller
@jeremydmiller
Do an IFamilyPolicy of your own that’s smart enough to rig that up is my best suggestion
Bryan Boettcher
@bryanboettcher
injecting IService<User> or IService<Option<User>> should both get satisfied by my ServiceClass<T>, because that implements IService<T> and IService<Option<T>>
oooh, ok
that gives me a place to look
Jeremy D. Miller
@jeremydmiller
Also, you get my standard lecture that IRepository<T> kind of strategies are more harmful than helpful in general
Bryan Boettcher
@bryanboettcher
we're probably in agreement on that but do you have a link to your rant on it?
or tldr it?
Jeremy D. Miller
@jeremydmiller
Lamar doesn’t do any kind of magic that would result in the behavior you described above
I don’t think I’ve ever blogged it. Unnecessary complexity, and it sets you up for potential performance problems by hiding all the advanced functionality of your persistence tooling.
Bryan Boettcher
@bryanboettcher
eh
i've seen what happens when you let the masses directly access the ORM
solutions get "clever"
Jeremy D. Miller
@jeremydmiller
I’ve seen people shoot themselves in the foot by wrapping IRepository<T> around the ORM. Get not stupid devs.
Bryan Boettcher
@bryanboettcher
yes hmm never thought of that as my position of "not a hiring manager" :)
Jeremy D. Miller
@jeremydmiller
My take is really just that adding extra complexity and ceremony to “force” devs to do the right thing causes more harm than good.
Jeremy D. Miller
@jeremydmiller
Anyway, what I’d do the open generics ConnectImplementationsToTypesClosing() trick in scanning for ForwardingRepository to one of its interfaces, then use a custom IFamilyPolicy to build a forwarding registration as necessary from the other interface. That family policy could be smart enough to unwind the monad for you.
LP
@grofit
Not sure if I am just being an idiot but trying to follow the docs in the registration section and for the life of me I cannot get the container to act like shown in the deferred registration approach i.e container.Configure(c => c.For....) it seems to only let you use Configure with an IServiceCollection which seems to be the default .net DI stuffs which doesnt have For etc on there
I am running this manually from what may as well be a class library, similar to if I was to manually create the container for a console app and use it from there
Jeremy D. Miller
@jeremydmiller
Why do you need to use IContainer.Configure()? My strong recommendation is to never use that, and it’s there mostly because at least at one time I had to do that for ASP.Net Core compliance
LP
@grofit
erk
so long story short its an app with a plugin architecture
Jeremy D. Miller
@jeremydmiller
Okay, gotcha
LP
@grofit
without going down the rabbit hole the app has a DI abstractor as it may be used on different platforms etc, so the framework needs to initialise with certain bits which need resolving, then it delegates to plugins, which then need to load etc
Jeremy D. Miller
@jeremydmiller
Any reason why the plugins can’t be found as part of application & container bootstrapping? It’s clumsy, but you can use your own ServiceRegistry, then copy the registrations to the end of IServiceCollection in the Configure() method
So:
LP
@grofit
tbh im not sure if I will be able to get it working as at the moment it only has the notion of a container in the abstraction layer, and most DI frameworks now separate bind/resolve phase objects
Jeremy D. Miller
@jeremydmiller
var registry = new MyServiceRegistry();
container.Configure(x => x.AddRange(registry));
LP
@grofit
possibly, we have the notion of modules already which is basically same as the service registry
it was originally modelled around Ninject and Zenject
Jeremy D. Miller
@jeremydmiller
Gotcha. Different ballgame. If you’re moving it around, could you use Scrutor maybe and write directly to the IServiceCollection as part of bootstrapping?
LP
@grofit
I cant really use IServiceCollection as it doesnt support all use cases :(
like contextual binding or activation callback/method (not sure if Lamar supports latter)
i.e lets say I have a registry for serialization/deserialization which can have the notion of "known types" and the core/plugins etc all add to the known types then before it can be used it needs to basically build an internal cache of all those types, it ideally needs to (before anything else uses it) run its initialization phase. You could put this in a constructor but lets assume there is some reason why its a separate method which needs running.
Jeremy D. Miller
@jeremydmiller
It doesn’t, sorry. I purposely left all of that out as part of moving StructureMap to Lamar to have a simpler, more supportable tool. That admittedly means leaving some flexibility behind in favor if better performance and fewer GitHub issues for me to deal with:)
LP
@grofit
yeah no worries, in some cases it can be worked around, as it was a requested addition so we put it in as our target frameworks at the time supported it
but there will still be some complex-ish bits going on, anyway thanks for your time buddy
Jeremy D. Miller
@jeremydmiller
Good luck with it