Wednesday, December 18, 2013

Dependency Injection Automatic Factories

One of the features of the Unity Application Block is automatic factory construction. What this means is if you configure Unity to resolve type Abc, then Unity also knows how to resolve Func<Abc>.

This allows using lazy evaluation of injected properties. The code below shows how to use an automatic factory.

private Abc abc = null;
public Func FuncAbc { get; set; }
protected Abc Abc
        if (abc == null && FuncAbc != null) abc = FuncAbc();
        return abc;

When the code accesses Abc the getter checks the underlying private field abc to see if it is null. If it is null, then the code checks to make sure the factory FuncAbc is not null. If the factory is not null then it creates a new instance by calling the factory FuncAbc.

Wednesday, May 8, 2013

I am presenting a talk entitled Refactoring To Allow Unit Testing at code camp.

Sunday, February 24, 2013

I submitted three talks to Philly.Net Code Camp
  • Improving the Quality of Code
  • Refactoring To Allow Unit Testing
  • Calling an Unsigned Assembly from a Signed Assembly
Hopefully I will be selected to give at least one.

Sunday, January 27, 2013

Powershell is a fun tool. Here is a one line command to select a random line out of a text file. Assuming you have a text file with the file name of "names.txt" the following command will pull one line out of the file at random.

Get-Content names.txt | Get-Random