开发者

Best IoC practices in large projects

What techniques have you found useful for managing dependencies of开发者_StackOverflow large projects with Inversion of Control containers?

Do you bootstrap everything in one place, or do you split it up?

Do you ever use multiple containers?


From an architectural viewpoint it's important to maintain a razor-sharp focus on where your Composition Root is. It should be as close to the application's entry point as at all possible, and you should compose the entire dependency graph in a single place.

Doing otherwise can create confusion about responsibilities, and you also risk to introduce all sorts of subtle bugs because the IFoo instance resolved in one place may or may not be the same as an IFoo instance resolved in another place.

If the application is so large that resolving an entire dependency graph in one go simply is prohibitively expensive, you can address this by using lazy loading lifetimes in strategic places (around Aggregate Services).

Conceptually, I always only have a single container. (I occasionally have multiple parent/child containers in play to break some circular dependencies, but that's an implementation detail.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜