开发者

Calling Method of a Class within StructureMap Registry Configuration

I can't help but think there is a better way to do this than my current code within my StructureMap Registry.

开发者_JS百科
  For<ISchedulerFactory>().Use(() => new StdSchedulerFactory());
  For<IScheduler>().Use(() => new StdSchedulerFactory().GetScheduler());

Is there a way to have it use the previous registered type and call the method from that? (GetScheduler() is on ISchedulerFactory interface)


Yes, you can do this:

For<IScheduler>().Use(c => c.GetInstance<ISchedulerFactory>().GetScheduler());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜