0

I have a ASP.NET web application (not MVC) which is actually a CMS application. I'm trying to set up StructureMap IoC framework and it's working well, but I've now hit a blocker in my understanding.

In my understanding, StructureMap enforces a pattern where all dependencies are registered in the core application assembly, so underlying assemblies do not themselves have a dependency on StructureMap.

So, say my application is My.App and it references another assembly My.Logic. My dependencies are all registered in a Container in My.App. This means that a class in My.Logic can take injected dependencies using a constructor like this:

public class Foo
{
  private readonly IBar bar;
  public Foo(IBar bar)
  {
    this.bar = bar;
  }
}

But now I have a case where my class in My.Logic is a type which must be registered in the CMS, and this requires that it has an empty constructor.

So the problem is, if I can't inject using constructor parameters, and My.Logic doesn't have a dependency on My.App so I don't have access to the IoC container, is it possible to use StructureMap to handle this scenario?

If not, what alternative do I have other than create the class within the same assembly as the IoC container?

Tom Troughton
  • 3,941
  • 2
  • 37
  • 77

1 Answers1

0

Use setter injection. See here

For<IBar>().Use<MyBar>();

Policies.FillAllPropertiesOfType<IBar>();
ozczecho
  • 8,649
  • 8
  • 36
  • 42