Tuesday, December 30, 2008

I have read (or tried to read) other WPF books but this one is by far the easiest one to learn from, both in terms of readability (the colors really make a difference) and contents. It feels like each page has a gem of information. If I were to buy only one book about WPF, this would be the one.

Friday, December 26, 2008

I am trying to use the Composite Application Guidance (aka Prism or Composite WPF) for an application at work. It all sounded very interesting and easy to use, but when the rubber hit the road it turned out that I needed to be educated in some of the concepts it uses. For instance, I was not familiar with Dependency Injection. Prism uses Unity as the DI container and I thought I'd highlight some examples on how to use the Unity container:

The first line is a type mapping. Anytime you need IModule, the container will return a ConcreteModule.The second line requests a new instance of ModuleA. ModuleA is not registered with the container. But Unity will look at ModuleA's constructor and see that it needs a IModule. It will then inject an instance of ConcreteModule because of the 1st line's mapping.Type Mapping - Singleton:

The object databases will contain two objects; one of type SQLDatabase and one of type OracleDatabase.Adding instances to the containerUse container.RegisterInstance to add pre-created objects to the container. Unity assumes that these objects are to be kept as singleton.

Here we're injecting dependencies through the Configure method of the container. Since the connection string is constructor parameter, we must use the InjectionConstructor class, and because Logger is just a property in GenericDatabase, we use the InjectionProperty class.Nested containers

If the child container doesn't have what you're asking from it, it will look at the parent container.To register child containers: