Problems with a Dependency Injection Container - Simple Injector

1

I am mounting my ID container using the Simple Injector, but it is giving a compilation error (Underline red) in the config. of the IReadOnlyRepository Interface with the ClientDapperRepository class. I think I'm doing something wrong but I do not know what is rsrsrs.

Does anyone know how to help me?

// Codes

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

        container.Register<IReadOnlyRepository, ClienteDapperRepository>(Lifestyle.Scoped);

        return container;
    }



     public interface IReadOnlyRepository<TEntity> where TEntity : class
     {
         TEntity Get(int id);
         IEnumerable<TEntity> All();
         IEnumerable<TEntity> Find(Expression<Func<TEntity, bool>> predicate);
     }



    public class ClienteDapperRepository : Common.Repository, IClienteReadOnlyRepository
    {
        public IEnumerable<Cliente> All()
        {
            using (var cn = SistemaComercialConnection)
            {
                var cliente = cn.Query<Cliente>("Select * from Cliente");
                return cliente;
            }
        }

    }
    
asked by anonymous 06.12.2017 / 00:29

1 answer

0

What happens is that your call to container.Register is wrong, you are trying to do dependency injection using as if the register was generic, where the correct one is that it expects 3 parameters, having to stay as follows its dependency injection.

container.Register(typeof(IReadOnlyRepository<>), typeof(ClienteDapperRepository), Lifestyle.Scoped);
    
06.12.2017 / 00:55