1
I am mounting my ID container using Simple Injector, but it is giving a compilation error (Underlined in red) in config. from the Ireadonlyrepository interface with the Clientedapperrepository class. I think I’m doing something wrong but I don’t know what rsrs are.
Someone knows 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;
            }
        }
    }
						
The name is not wrong?
– novic
The names are right, but he doesn’t accept this structure... I don’t know if there’s any other way...
– Master JR
can send the error code?
– Brewerton Santos
If I leave it as it is, it just stands underlined in red. If I change to container.Register<Ireadonlyrepository<Client>, Clientedapperrepository>(Lifestyle.Scoped); It generates this error: "+ $Exception {"To be Able to use the Lifestyle.Scoped Property, Please ensure that the container is configured with a default scoped lifestyle by Setting the Container.Options.Defaultscopedlifestyle Property with the required scoped lifestyle for your type of application. See: https://simpleinjector.org/lifestyles#scoped"} System.Invalidoperationexception "
– Master JR
Please post the code instead of images. And if you look at the build output, you will see the error, post it too
– Pablo Tondolo de Vargas
I think the way I’m doing it is wrong...
– Master JR
your second Register wouldn’t have to look like the first one? Getting something like
container.Register(typeof(IReadOnlyRepository<>), typeof(ClienteDapperRepository<>, Lifestyle.Scope)– Pablo Tondolo de Vargas
I posted the Personal Code.
– Master JR
I tried it like this: container. Register(typeof(Ireadonlyrepository<>), typeof(Clientedapperrepository<>), Lifestyle.Scoped); but it underlines in red the Clientedapperrepository.
– Master JR
Suddenly the error pq tua classs Clientedapperrepository is not generic, so it has to be as follows
container.Register(typeof(IReadOnlyRepository<>), typeof(ClienteDapperRepository), Lifestyle.Scoped);– Pablo Tondolo de Vargas
If I were to use Ninject, just use: Bind<Ireadonlyrepository<Genre>>(). To<Genredapperrepository>(); that would work.... Only there must be some difference in the Simpleinjector...
– Master JR
Pablo, it worked bro!!!!!!! Thank you very much dude!!!!!!!!!
– Master JR
Answer there on the topic of the question so I can mark as answer.. :)
– Master JR
I just think you could improve your question by taking the pictures and putting the error message you had. But leaving the code.
– Pablo Tondolo de Vargas
I just edited it! Thank you!
– Master JR