c# WCF [Simple Injectior] injection pattern -


i have seen lots of examples on how this, newbie di, thought best ask question issues. again, apologize if has been asked already.

we have c# wcf service working, have been asked implement di framework reuse ability. after looking around have chosen simple injector.

so service compiles , can view wsdl browser.

to start have placed initialization code sets container in global.asax file in application_start function. within function have following code:

var container = new container(); container.options.defaultscopedlifestyle = new wcfoperationlifestyle(); 

followed registrations:

container.register<ipersonmanager, personmanager>(); etc.... 

finally, run:

simpleinjectorservicehostfactory.setcontainer(container); 

this runs correctly, no errors , can break point onto fisrt line above , step through code.

i have been told should use different location initialization code , not use global.asax file. not sure if should change this.

ok.

when @ constructor personmanager class, passing object implements ipersonmanager interface.

i assuming correct way of doing this. long object implements ipersonmanager interface injected in. not sure either

anyway,

i have class, code follows:

public static class addressrepository {     public static void setaddress(this irepository<address> addressrepository)     {         throw new notimplementedexception();     } } 

and have tried set simple injector initialisation follows:

container.register(typeof(irepository<>), typeof(address), lifestyle.scoped); 

this not work. guess because addressrepository not implement interface, method does.

is possible inject method , if how done.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -