.net - How to wire up a generic repository parameter -


i'm getting following error:

none of constructors found 'autofac.core.activators.reflection.defaultconstructorfinder' on type 'hotelslive.application.companyservice' can invoked available services , parameters:

cannot resolve parameter 'hotelslive.interfaces.repositories.irepositoryasync1[hotelslive.domain.models.company] repository' of constructor 'void .ctor(hotelslive.interfaces.repositories.irepositoryasync1[hotelslive.domain.models.company])'.

the service constructor is:

    public companyservice(irepositoryasync<company> repository) : base(repository) {         _companyrepository = repository;     } 

the autofac registrations are:

        builder.registertype<companyservice>()                             .as<icompanyservice>()                             .instanceperrequest(); 

and

        builder.registergeneric(typeof(repository<>))                 .as(typeof(irepositoryasync<>))                 .instanceperrequest(); 

i'm assuming need specify parameter, not sure how go this. i've looked withparameter method on comapnyservice registration, haven't been able compile.

eventually got there. final consfiguration was:

        builder.registertype<companyservice>()                             .as<icompanyservice>()                             .withparameter(new resolvedparameter((p, c) => p.name == "repository", (p, c) => c.resolve<irepositoryasync<company>>()))                             .instanceperrequest(); 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -