c# - Windsor Setter Injection in code -


i'm using windsor ioc in our .net project, i'm having difficulties doing setter injection in code.

i believe comes fact blanket register components, since i'm hoping legacy project ioc compliant , unit tested (sweet dreams!).

here how i'm registering daos:

container     .register(alltypes.fromassemblynamed("myapp.business")     .where(component.isinnamespace("myapp.business.dao"))     .withservice.defaultinterface()); 

and here how i'm registering components using daos:

container     .register(alltypes.fromassemblynamed("myapp.business")     .where(component.isinnamespace("myapp.mycomponentobject"))); 

i hoping setters picked automatically in components, resources found seem show setters need defined.

unfortunately i've found examples of how in configuration xml, not in code.

i found how add parameter component in code there seem limitations. looks has string , if that's not case, seems force me declare components 1 one instead of blanket registering. code become huge if had , somehow windsor lose of appeal me.

i remember using spring if bean declared autowiring inject without issue.

am missing w/ windsor here?

===============

more information:

in component class use dao component here how declare setter:

private imydao dao = null;  public imydao dao {   set { this.dao = value;  } } 

the main reason want setter inject because can't change constructors without having pretty impact on legacy app.

===============

update:

have commented out of registration code, left see if works in simple case scenario , did not:

//daos container.register(  component.for<imydao>()   .implementedby<mydao>()     .named("mydao"),  //components component.for<mycomponentobject>()   .parameters(parameter.forkey("dao").eq("mydao"))); 

i put break point code bombing , on set of property , dao dependency still null in component , set line of property never called.

castle windsor's setter injection work properly.

[testclass] public class setterinjectiontest {     [testmethod]     public void testmethod1()     {         var container = new windsorcontainer();         container.register(component.for<iserviceb>().implementedby<serviceb>());         container.register(component.for<iservicea>().implementedby<servicea>());         var servicea = container.resolve<iservicea>();          assert.istrue(servicea.ispropertyinjected());     } }  public class servicea : iservicea {     public iserviceb b { get; set; }      public bool ispropertyinjected()     {         return b != null;     } }  public interface iservicea {     bool ispropertyinjected(); }  public class serviceb : iserviceb{} public interface iserviceb{} 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -