views:

223

answers:

1

I have a home-grown framework that includes a simple ServiceLocator class implemented using a static Dictionary. It was developed for a WinForms environment and did what I wanted just fine.

This proves to be a disaster when using the framework in as ASP.Net framework; the Dictionary, a static variable, is instanciated upon first use and every ASP.Net application uses the same dictionary. This is NOT my design intent.

For example, the a web application attempts to register a DB Audit Service, IAuditService. Error!! The service is already registered by the first user! Just the tip of the static variable problems that can occur in a ASP.Net environment.

I have experimented with Autofac IOC. Can I avoid my static variable problems by using Autofac (or some other IOC)?

BP....

A: 

You can use an IOC framework, but if you want the object to stick around you will have to store it yourself, otherwise you will just be asking for a new object each time from the IOC Container.

CSharpAtl
I DON'T want the object ( that is, the service registrations) to stick around longer than the current request. The registrations for the current request request need to be independent from any other requests that may need an implementation a specific interface.BP....
theBruce
then you can use the IOC container...I use StructureMap and it has helped my software design greatly.
CSharpAtl