5

I implemented a interface injection using StructureMap as describe below.

ObjectFactory.Initialize(x => { x.For<*IRepository*>().Use<*SQLRepository*>(); });

But it is giving a warning as follows

Warning 2 'StructureMap.ObjectFactory' is obsolete: 'ObjectFactory will be removed in a future 4.0 release of StructureMap. Favor the usage of the Container class for future work'.

How do I correct this by using Container class

Richard Ev
  • 52,939
  • 59
  • 191
  • 278
abn
  • 73
  • 1
  • 9
  • http://stackoverflow.com/questions/25550914/how-to-use-container-instead-of-objectfactory-in-structuremap-serviceactivator ? – Mark Jun 09 '15 at 04:42
  • http://dennisrongo.com/resolving-the-structuremap-objectfactory-is-obsolete-warning-message/ – CodingDefined Jun 09 '15 at 04:42

1 Answers1

11

You can create an instance of a container directly, per their documentation. The syntax is relatively similar.

var container = new Container(x =>
{
    x.ForRequestedType<IRepository>().Use<SQLRepository>();
});
Lovethenakedgun
  • 731
  • 6
  • 22
David L
  • 32,885
  • 8
  • 62
  • 93