views:

13

answers:

1

If i have N numbers of classes on each of them i am declaring for example property which contains some app setting values from config file.

  public static IAppSettings AppSettings { get; set; }

I want to populate this property automatically when class is created.

I am thinking to achieve this goal using StructureMap.

I want to "say" somehow only in one place, that if class contain this property populate it.

May be some one came across this and have any ideas?

ASP.NET/ASP.NET MVC, ConsoleApp/WinForms

A: 

If i have N numbers of classes on each of them i am declaring for example property which contains some app setting values from config file.

You should consider having those N classes derive from a base class which contains this property:

public abstract Base
{
    public IAppSettings AppSettings { get; set; }
}

then if you want to have this property automatically populated by StructureMap you should no longer instantiate them manually but always ask the container for a value.

For example in a ASP.NET MVC application I would use constructor injection to pass the value of IAppSettings to all the controllers that need it.

Darin Dimitrov
I think i am looking for something like that http://dotnet.dzone.com/articles/property-injection but i cant get it work.
Greon