Class call method in StructureMap configuration configuration

I cannot help but think that there is a better way to do this than my current code in my StructureMap registry.

  For<ISchedulerFactory>().Use(() => new StdSchedulerFactory());
  For<IScheduler>().Use(() => new StdSchedulerFactory().GetScheduler());

Is there a way to use the previous registered type and call a method from this? (GetScheduler () is in the ISchedulerFactory interface)

+3
source share
1 answer

Yes you can do this:

For<IScheduler>().Use(c => c.GetInstance<ISchedulerFactory>().GetScheduler());
+4
source

Source: https://habr.com/ru/post/1771797/


All Articles