I use Windsor to do IoC in our .Net project, but I'm having difficulty installing injections in the code.
I believe that this is due to the fact that I put on my components, because in the end I hope that the old project will be fully compatible with IoC and basically Unit Test (sweet dreams!).
This is how I register DAO:
container
.Register(AllTypes.FromAssemblyNamed("MyApp.Business")
.Where(Component.IsInNamespace("MyApp.Business.Dao"))
.WithService.DefaultInterface());
And this is how I register components using DAO:
container
.Register(AllTypes.FromAssemblyNamed("MyApp.Business")
.Where(Component.IsInNamespace("MyApp.MyComponentObject")));
I was hoping that setters would load automatically in components, but the resources I found indicate that setters should be defined.
Unfortunately, I found examples of how to do this in the XML configuration, and not in the code.
, , , , . , , , , . , , - .
, Spring , bean, autowiring - .
- ?
===============
:
, Dao, :
private IMyDao dao = null;
public IMyDao Dao
{
set { this.dao = value; }
}
, , - , , .
===============
Update:
, , , , :
//DAOs
container.Register(
Component.For<IMyDao>()
.ImplementedBy<MyDao>()
.Named("myDao"),
//Components
Component.For<MyComponentObject>()
.Parameters(Parameter.ForKey("Dao").Eq("myDao")));
, , set , DAO - null , set .