views:

32

answers:

0

Hi

I've got a rookie question about StructureMap. In my app, on startup, I load a bunch of settings, in a list, from the DB, which all my threads will need to access at one time or another. So I wonder, can I make the list a singleton and share across my injections like so:

//Class for task
public class MyTask1 : IMyTask1 
{ 
  public MyTask1(List<Setting> _settings, ISomeRepo1 _repo){}
}

//Load from db
List<Setting> settings = Repo.GetSettings();

//This does not work
ObjectFactory.Configure(x =>
{

     x.For<List<Setting>>().Singleton().Use(() => Repo.GetSettings());
     //Neither does this
     x.For<List<Setting>>().Singleton().Use(settings);

     x.For<IMyTask1>().Use<MyTask1>();
     x.For<IMyTask2>().Use<MyTask2>();
};

//This does work
ObjectFactory.Configure(x =>
{
     x.For<IMyTask1>().Use<MyTask1>()
         .Ctor<List<Setting>>().Is(settings );
     x.For<IMyTask2>().Use<MyTask2>()
         .Ctor<List<Setting>>().Is(settings );
};

I would like to avoid the: .Ctor<List<Setting>>().Is(settings );
for every task I setup in SM.

Does anybody know of way of doing this without creating a class to wrap the setting list?

Kind regards Garrett