简体   繁体   中英

Resolving dependencies with windsor castle

I have a factory class with dependencies on a repository class. How do I resolve the dependencies within my factory class? I could pass the dependency from my controller into the factory, but that doesn't seem like the right way.

public BarFactory(IFoo foo) {

}

For controllers you can just stick the dependencies in the constructor and the controller factory deals with it, but for everything else I'm not so sure.

Thanks!

If you need a factory when using windsor the recommended approach would be to use the TypeFactoryFacility. You can find all about it in this link: http://docs.castleproject.org/Windsor.Typed-Factory-Facility-interface-based-factories.ashx

In general it is much easier then writing your own factories. Just create the interface and Windsor does the heavy lifting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM