Winter4Net - .NET lightweight IOC container

WINTER4NET is lightweight .NET "Inversion of Control" container (IoC, aka dependency injection):

  • Based on .NET System.ComponentModel interfaces
  • Ultrafast, compact and scalable
  • Infrastructure for MDD/MDA

Getting Started - ASP.NET and Winter Integration

You can download our free binary package, which also includes samples. Or you can just go through this short getting started article that describes how to integrate Winter IoC container with any ASP.NET application.

Step 1: Define Winter configuration section in Web.config

It's very natural to place components definition used in ASP.NET application into Web.config file, so in simplest case your web.config should look like:

After that you can obtain IComponetsConfig instance by calling 'System.Configuration.ConfigurationSettings.GetConfig("components")'.

Step 2: Configure container creation in Global.asax

Because container will be used almost for every request to your ASP.NET application good idea to place container initialization code to Global.asax file:

In this code we define property AppComponentsConfig for accessing IComponentsConfig instance; in its getter we store instance obtained from ConfigurationSettings in application context to avoid excessive config parsing on every HTTP request. 'BeginRequest' event handler contains code that initialized application container and service provider for current request (so container instance will be created on every request - this means that you should care about thread-safety of your components). 'AcquireRequestState' event handler adds current HTTP request handler to our container (if it implements IComponent interface). In most cases handler is an instance of System.Web.UI.Page class (which is implements IComponent) and will be added to the container. This means that you can use Page.Site anywere inside pages/user controls to access your components by Service Locator pattern.

Step 3: Place you components definitions

Just add necessary definitions to 'components' section of your Web.config file:

Syntax is similar to SpringFramework (main difference is that 'bean' tag replaced with 'component' tag); for complete schema you may refer to 'Docs/ComponentsConfigSchema.xsd' in the package.

Step 4: Use components from ASP.NET Page

Any instance from your Winter configuration can be easily accessed in following manner:


These samples should not be considered commercial quality applications. They are just intended to illustrate how to use some particular feature, or group of features in Winter4Net. Please feel free to polish them into applications of your own, or extract sections to use in your own code.