Doubt about Mapping an Interface with a Class - SimpleInjector

1

I'm having trouble mapping Interface IClienteRepository to class ClienteRepository . When compiling the application, this error appears:

  

"exception {" To be able to use the Lifestyle.Scoped property, please ensure that the container is configured with the default lifestyle set by the Container.Options.DefaultScopedLifestyle property with the required lifestyle scoped for your type of application. See: link "} System.InvalidOperationException"

How to solve?

public static Container RegisterServices(Container container)
    {
        //Domain to Repository

        container.Register<IClienteRepository, ClienteRepository>(Lifestyle.Scoped);

        return container;
    }

public interface IClienteRepository : IRepository<Cliente>
    {
    }

public class ClienteRepository : Repository<Cliente>, IClienteRepository
    {
        public ClienteRepository(SistemaComercialContext context)
            :base(context)
        {

        }
    }
    
asked by anonymous 06.12.2017 / 10:02

1 answer

0

As you can see in the simpleinjector documentation, for you to use Lifestyle.Scoped , you you must first make sure the continer.Options.DefaultScopedLifestyle option is properly set.

Getting something like this

public static Container RegisterServices(Container container)
{
    // Set the scoped lifestyle one directly after creating the container
    container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();          
    //Domain to Repository

    container.Register<IClienteRepository, ClienteRepository>(Lifestyle.Scoped);

    return container;
}
    
06.12.2017 / 11:36