2
votes

When I register the following in SM and then attempt to create an instance I get the exception - 'StructureMap Exception Code: 202 No Default Instance defined for PluginFamily...'

Scan(x =>
        {
            x.Assembly("MVCDemo");
            x.Assembly("MVCDemo.Infrastructure");
            x.Assembly("MVCDemo.Services");

            x.AddAllTypesOf(typeof (IRepository<>));
        });

        ForRequestedType<IRepository<Employee>>().TheDefault.Is.ConstructedBy(() => new EmployeeRepository());


 var tmp4 = ObjectFactory.GetInstance<IRepository<Employee>>();

The exception occurs when I try and get an instance of IRepository.

Does anyone know what I'm missing?

Cheers

Ollie

2

2 Answers

5
votes

The answer is I shouldn't use ObjectFactory to create instance, I should use the container:

var container = new Container(new MvcDemoRegistry());
var cultureProvider = container.GetInstance<IProvideCultureInfo>();

Ta

Ollie

2
votes

You aren't supposed to use containers to get instances when using an IoC and DI. You should be using constructor injection and have the IoC handle the injection for you.