asp.net mvc - How to (not) specify scope in class libraries with Ninject3 -


i've asp.net mvc application using ninject3 (nuget install). solution contains:

  • an mvc project (composition root);
  • a domain model project;
  • a data layer project;
  • a scheduler project (running scheduled jobs within windows service , holding alternative composition root);
  • some other projects.

i'm following approach have many small modules spread across projects defining bindings. 2 composition roots use same bindings.

i cannot figure out how configure scope modules within class libraries. example, given these bindings:

bind<idomainservice1>()   .to<service1impl>()   .insingletonscope(); //this should singleton  bind<idomainservice2>()   .to<service2impl>(); //no scope specified 

i want single instance of service1impl, whereas scope service2impl should depend on composition root used. mvc project should have inrequestscope() service2impl (and other bindings unspecified scope). scheduler project, not run within http context, should use inthreadscope().

is approach correct? if yes, right way of configuring behaviour?

in ninject, not specifying scope means intransientscope().

your choices either duplicate bindings or create custom inscope() scoping rule binding.

the cleanest solution (especially given mvc in play) create plugin slots inrequestscope() mechanism.

there createscope() method has minimal documentation in ninject.extensions.namedscope readme, used like this. requires select 'include prerelease' in nuget. (and should writing wiki article on have many other things on plate...)


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -