BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Microsoft Enterprise Library 4.0 will get a dose of Dependency Injection

Microsoft Enterprise Library 4.0 will get a dose of Dependency Injection

The next version of the Microsoft Enterprise Library, v4, will support dependency injection out-of-the box.  Dependency Injection will be provided in containers both separately and part of the library.

It's important to note that the next release of the Enterprise Library was going to be v3.5 but was changed to be v4.0 due to the amount of core changes to the library.  Grigori Melnik, the Product Manager in the Microsoft Patterns & Practices group gives his reasons for the version change:

As to the Enterprise Library version change, yes, originally, we only planed to do minor enhancements and fixes. DIAB was a separate project in our product backlog. Based on the recent feedback from customers at the Patterns & Practices Summit, correspondence with Enterprise Library enthusiasts, comments from other teams at Patterns & Practices and CodePlex, plus people's constructive blog postings and suggestions it made sense to address the dependency injection story now – so we’ve included it in the coming release of Enterprise Library and that's not a minor change. Thus, v4.

What is Dependency Injection, as explained on Wikipedia:

Dependency injection (DI) is a programming technique, sometimes also (incorrectly) referred to as inversion of control or IoC, even though, technically speaking, dependency injection specifically refers to a limited-scope implementation of a particular form of IoC.

Dependency injection is where the implementation of one class is actually performed partially by another - the injected class (see the example below). Typically there are multiple variants (sub-classes) of the injected class. The main class abstracts out the common code required by all implementations and delegates to the injected class where specific behavior is required.

Inversion of Control is where a program gives up control of its own execution and simply responds to requests made of it (typically in the form of events). In the same way, a class using dependency injection gives up control over some of its implementation and lets the injected class do the work.

Dependency Injection is not a new technology, but has experienced popularity recently.  A good introduction can be found in an article written by Martin Fowler of ThoughtWorks. 

Microsoft views the importance of adding dependency injection to the Enterprise Library to take advantage of the benefits of modular design:

The benefits of modular design with cohesive components that have little or no coupling to the rest of the software system are commonly recognized today. Dependency injection is a mechanism that facilitates such aggressive decoupling and independence of components. Lightweight dependency injection containers help assemble components (potentially from different projects) into a cohesive application at runtime and promote code reuse.

Microsoft has a long history of incorporating modular design into their application blocks:

The values of modular design implemented with support of dependency injection have been long recognized and embraced by Microsoft patterns & practices. Originally, implemented for the Composite UI Application Block (CAB) and later for the Enterprise Library v2 (back in early 2006), the ObjectBuilder pipeline allows to customize how objects are created at runtime. The current Enterprise Library configuration system is based on a DI container created using ObjectBuilder.

Version 4.0 of the Enterprise Library will include much redesign and refactoring. 

With the upcoming version of EntLib (v4), we are planning to provide containers (flat and hierarchical) that will support dependency injection out of the box. These containers will be packaged individually and also with EntLib v4. Furthermore, to demonstrate the effective use of dependency injection on a real world project, we plan to refactor individual EntLib blocks and abstract away configuration code (configurators). We will build an EntLib facade that will have individual configurators injected in it as needed. A client app can go through this facade to request services while all wiring of objects necessary for those services to run will be handled by the DI container. This will not only make the design cleaner but will also make it easier to use and configure only those application blocks that you desire.

Some existing .NET application frameworks already support dependency injection and will be able work with the new application blocks including:

An organization using these containers will be able to leverage the new Enterprise Library into their existing infrastructure.  Anyone using an existing version of the Enterprise Library will be able to upgrade to the new version without breaking their code.

More information about the Microsoft Enterprise Library can be found at the Microsoft Patterns & Practices web site.  There has been no release date announced for version 4.0 of the library.

Rate this Article

Adoption
Style

BT