views:

79

answers:

1

When I started to learn about WPF and MVVM recently, I came across some sort of framework or technology in .NET that made it really easy to request a service of some kind. In my particular case, I've got an assembly that handles writing application preferences to an XML file, and I want to let all of my assemblies in the larger application use this to write their own set of preferences to the same file.

I thought it was Unity, but when I looked it up, it didn't seem to be what I read about. The only clue I have for you is that I think it's called a service (it's NOT WCF), and you can request the service two ways: one way gives you the same service each time, like a singleton, and the other way gives you a new instance each time.

Please help to jog my poor memory. :)

+1  A: 

My guess is that you're referring to Microsoft's Common Service Locator.

Although you might just be talking about Dependency Injection in general, of which Unity is one such library. There are many other DI libraries including AutoFac, Ninject, StructureMap, and Castle Windsor. The CSL is just a way of abstracting the DI library itself, which is useful when you're a framework/library designer and want to use DI without depending on a specific implementation.

Aaronaught
Thanks, Castle Windsor was it!!! I guess I could be well-served by any of the other libraries that you had mentioned. I am very new to this sort of thing, so maybe I should just give CSL a try? DI is really no different than if I passed in an interface to my preferences library to the assemblies that need it, right? It's just a heck of a lot cleaner, right?
Dave
@Dave: CSL isn't actually a DI library, it's just a wrapper for any of those other libraries. Unless you yourself are designing libraries intended for reuse, there's no reason to bother with the CSL (Microsoft actually says that explicitly although I can't find the page at the moment). And, DI isn't a way of *passing* interfaces, it's a way of abstracting their *instantiation*. But you should read the DI article, there's not enough room in a comment box to describe it in detail. ;)
Aaronaught
Yes, I understand that they aren't for passing interfaces, I was just asking for confirmation that they are an elegant alternative to passing interfaces. Coming from C++ land, the latter is all I know how to do. DI sounds like a good replacement. I'll read the articles, now, thanks! :)
Dave