2

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 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.