Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Yair Halberstadt
    @YairHalberstadt
    Hi all.
    I tend to hang around on gitter a lot, so if you have any questions, suggestions, or issues relating to stronginject, just @yairhalberstadt me and I'll try my hardest to help as soon as possible!
    I'm in GMT+2 timezone, sleep at night, and am not available on saturdays, so you may have to wait up to a day or so for help if you're unlucky.
    Martin Vseticka
    @MartyIX

    @YairHalberstadt Hi Yair, I'm playing a little bit with StrongInject and I'm very interested how would one write something like:

    _ = builder.RegisterType<JoinableTaskFactory>().InstancePerLifetimeScope().IfNotRegistered(typeof(JoinableTaskFactory));

    (this is in Autofac)

    This is something which would allow me to make my tests very customizable (that .IfNotRegistered(typeof(JoinableTaskFactory)) part)

    Yair Halberstadt
    @YairHalberstadt
    Hi @MartyIX. Currently there's no way to provide a registration only as a backup registration if nothing else is registered. If necessary I could add it, although if be interested to understand more about what you're doing, and whether there's a solution which will work today?
    Martin Vseticka
    @MartyIX

    @YairHalberstadt Currently I have a set of integration/regression tests which do not use DIC. It got pretty big and when I change something, I need to modify these integration tests too. So I went ahead and used Autofac to wire my dependencies in the integration tests. Now these integration tests typically use "production dependencies" but often some parts need to be changed like:

    • a production URI -> a testing URI (that's easy with strong inject/autofac)
    • for some tests, it's useful to replace HTTP client implementation with a mock as that allows to simulate "hard-to-simulate" cases. But I need this for one test but not for others and I don't know a reasonable solution for this.

    So basically, I have a containter for my integration/regression tests and some dependencies need to be replaced on test basis.

    Did I explain it clear enough?

    Yair Halberstadt
    @YairHalberstadt
    @MartyIX So there's two solutions:
    1. you can inherit/import a container as a module to a new container, and then any registrations you add to the new container override those on the old container.
    2. if you don't want to define a new container each time, you can provide some sort of configuration for things you know you want to modify using a technique like so:
    
    [Register(typeof(MockService))]
    [Register(typeof(RealService), typeof(IService))]
    partial class Container : IContainer<Whatever>
    {
        private bool _useMockService;
        public Container(bool useMockService) => _useMockService = useMockService;
        [DecoratorFactory] public IService PickService(MockService mock, IService original) => useMockService ? mock : original;
    }
    Martin Vseticka
    @MartyIX

    Thanks! The second solution looks good.

    I know about the first one but then the number of container would grow really fast I think with the number of "decisions"