c# - Resolution of the dependency failed - Unity -
using unity / bootstrapper, i'm registering base of operations class - servicebase multiple concrete services.
container.registertype<servicebase, clearedpaymentservice>("clearedpaymentservice"); container.registertype<servicebase, missedpaymentservice>("missedpaymentservice"); i'm registering external service below this:
container.registertype<ipaymentservice, paymentserviceclient>("paymentservice"); the external service used in both clearedpaymentservice , missedpaymentservice shown below:
public partial class clearedpaymentservice : servicebase { private readonly ipaymentservice _paymentservice; private readonly ischeduler _scheduler; private timer _timer; public clearedpaymentservice(ipaymentservice paymentservice, ischeduler scheduler) { _paymentservice = paymentservice; _scheduler = scheduler; } ...etc } when come utilize 2 services, run trouble:
var container = (iunitycontainer)bootstrapper.container; var services = container.resolveall<servicebase>(); if (environment.userinteractive) { runinteractive(services.toarray()); } the code throws exception on "services.toarray()":
resolution of dependency failed, type = "system.serviceprocess.servicebase", name = "clearedpaymentservice". exception occurred while: while resolving. exception is: invalidoperationexception - current type, think.incomeprotection.thirdparty.service.contract.outbound.ipaymentservice, interface , cannot constructed. missing type mapping? @ time of exception, container was: resolving thirdpartypaymentinvoker.clearedpaymentservice,clearedpaymentservice (mapped system.serviceprocess.servicebase, clearedpaymentservice) resolving parameter "paymentservice" of constructor thirdpartypaymentinvoker.clearedpaymentservice(think.incomeprotection.thirdparty.service.contract.outbound.ipaymentservice paymentservice, thirdpartypaymentinvoker.ischeduler scheduler) resolving think.incomeprotection.thirdparty.service.contract.outbound.ipaymentservice,(none)
i understand error saying - constructor of clearedpaymentservice expecting concrete instance of ipaymentservice, hasn't been resolved reason...
i'm new unity, presume it's basic haven't understood yet!
any help appreciated.
thanks, alex
your registrations container provide name each service registered. there no default (not named) service unity can utilize in scenario.
to prepare remove names while registering thins. if on other hand wish utilize specific named service there attribute can add together on parameter of constructor [nameddependancy("your name")]. default should not utilize feature code simpler without it.
c# unity-container bootstrapper
No comments:
Post a Comment