Mar 31 2011

Beware of lifetime manager policy locks in Unity

Category: .NetRory Primrose @ 10:32
I have created a caching dependency injection slice in order to squeeze more performance from the DAL in a workflow service. What I found was that the service always hit a timeout when the caching slice was put into the Unity configuration. I spent half a day working with AppFabric monitoring, event logs and all the information I could get out of diagnostic tracing for WCF, WF, WIF and custom sources. After not being able to get any answers along with futile debugging efforts, I realised that I ... [More]

Tags: , , , , , ,

Oct 1 2010

Custom Windows Workflow activity for dependency resolution–Wrap up

Category: .NetRory Primrose @ 10:39
I have been writing a series of posts recently about implementing a custom WF activity that will provide dependency resolution support for WF4 workflows. The InstanceResolver activity caters for lazy loading dependencies, multiple resolutions on the one activity, workflow persistence (including support for non-serializable dependencies) and lifetime management of the resolved dependencies. The activity uses Unity as the backend IoC container however this could be modified to support a differ... [More]

Tags: , ,

Sep 16 2010

Custom Windows Workflow activity for dependency resolution–Part 1

Category: .NetRory Primrose @ 12:41
The previous post talked about the issues with supporting DI in WF4. The nature of Windows Workflow means that there is no true support for DI. Using a custom extension and activity will allow for pulling in dependencies to a workflow while catering for the concerns outlined in the previous post. This series will refer to the dependency injection concept as dependency resolution because this technique is more aligned with the Service Locator pattern than DI. This first part will go through the d... [More]

Tags: ,

Sep 15 2010

Dependency injection options for Windows Workflow 4

Category: .NetRory Primrose @ 11:42
I’m a fan of DI for all the benefits that it brings. Unfortunately dependency injection is not really supported with Windows Workflow. DI is a pattern in which dependencies are calculated outside an entity and provided to the entity for it to use. The DI container is responsible for creating and managing these dependencies and injecting them onto the entity. WF does not fully support this model. Any dependencies calculated outside a workflow must be provided to the workflow execution engine a... [More]

Tags: ,

Jul 27 2010

Tracking lazy loaded build trees in Unity

Category: .NetRory Primrose @ 08:31
I recently posted a Unity extension for disposing build trees created by Resolve and BuildUp actions. Unity has a feature that supports lazy loading injected dependencies that the original disposal extension didn’t cater for. Consider the following example. using System; using Microsoft.Practices.Unity; using Neovolve.Toolkit.Unity; namespace Neovolve.LazyInjectionTesting { class Program { static void Main(String[] args) { IUnityContainer containe... [More]

Tags: ,

Jul 12 2010

Canberra .Net Users Group Presentation next week

Category: .Net | ApplicationsRory Primrose @ 17:32
I’m going to be presenting at this months .Net Users Group in Canberra. The topic will be Unity injection for ASP.Net and WCF with some Unity extensibility added in as well. Here is the abstract for the session. Unity is the Microsoft Patterns and Practises implementation of an inversion of control (IoC) container. Using IoC containers facilitates the dependency injection pattern which helps to decouple code from its dependencies. A common way to implement IoC in ASP.Net and WCF servic... [More]

Tags: , , , ,

Jun 28 2010

Unity dependency injection for ASP.Net MVC2

Category: .NetRory Primrose @ 08:34
I knew that I should address the popular MVC model for ASP.Net as soon as I had finished my post on Unity dependency injection for ASP.Net. A different implementation for Unity injection is required here as the MCV model has a different method of processing ASP.Net pages. Like the posts for Unity injection with WCF and ASP.Net, there are similar implementations already published on the internet to support MVC. The main issues I have with the examples posted elsewhere are that: global.asax ... [More]

Tags: , , ,

May 19 2010

Unity dependency injection for ASP.Net

Category: .NetRory Primrose @ 10:39
I’ve been wanting to get dependency injection happening for ASP.Net pages like I have for WCF service instances (see here and here). The solutions that I found on the net use combinations of abstract ASP.Net pages or Global.asax with an IHttpModule. I didn’t like these solutions because it is messy to make multiple changes to your application to introduce a single piece of functionality. My version uses a single IHttpModule without any other dependencies. The only impact on the application is t... [More]

Tags: , , ,

May 17 2010

Unity dependency injections for WCF services – Part 2

Category: .Net | ApplicationsRory Primrose @ 16:23
In Part 1, I described the code used to leverage ServiceHostFactory to create WCF service instances with dependency injection via Unity. Using a custom ServiceHostFactory is a really easy way to get dependency injection in WCF but comes with two drawbacks. The standard Unity configuration section name (“unity”) must be used and named Unity containers are not supported. Most applications will work within these constraints. Using a configuration based service behavior is the answer to situations... [More]

Tags: , , ,

May 15 2010

Unity dependency injection for WCF services – Part 1

Category: .NetRory Primrose @ 10:26
There are a few ways that Unity can be used to construct WCF service instances. The options are poor mans injection, service host factories and configured behaviours. The poor mans injection option is to create a unity container within the constructor of the service type and resolve dependencies from within the service instance. This is not elegant and couples the IOC implementation (Unity in this case) to the service. The second option is to create a custom service host factory. This option a... [More]

Tags: , ,