Archive for the ‘IoC’ Category

Tinyject – IoC in an Evening

No Comments »

Last night, while hacking on the Aggressive project, I where in the need of a container. My initial idea was to try out Autofac, but since I was offline at the moment, I quickly hacked together a small container myself. Since I actually thought the look&feel of the interface was exactly what I wanted, I decided to put the source code in a separate project and give it a name; Tinyject. The code can be found here and is licensed under  the Apache License 2.0.

Features:

  • A Register() method in different flavors (including generic versions) for registering concrete types & interfaces in the type map.
    The Register() methods return this, so they can be chained.
  • A Resolve() method in different flavors (including generic versions) for resolving new and existing instances of registered types.
  • An idea of instance lifetime; Transient & Singleton.
  • Property, field and constructor injection.
  • The container implements System.IDisposable, and can be used in a using() { … } scope.
  • A static, thread-safe wrapper, TinyjectStatic.
  • A small number of xUnit-based unit tests to check the integrity of the stuff.

That’s it. At the moment there is no configuration system – and no extensibility points, but I believe the 2.0 version – maybe developed tonight after the baby swimming, will contain a simple extensible configuration model.

If anyone want to design a logo for it – please go ahead :-)

kick it on DotNetKicks.com


My Product / Idea Backlog

No Comments »

This post is a work in progress. I feel that I need a place to organize all my pet projects, whether they still only exist in my head or have materialized into some code.

  • Miles Platform

    • Active Directory FOAF Gateway – internal beta
    • Active Directory Photo Uploader – internal beta
    • MOAT (Meaning Of A Tag) service / client – idea
    • Internal Library service / client – prototype
  • WCF related

  • Miscellaneous

    • Agressive – Silverlight-based, lightweight Time Management System – planning/prototyping stage.
    • Visual Studio Theme Explorer – planning phase.
    • Tinyject – A tiny IoC/DI container in about 200 lines of C#.

The idea is to release as many of these under a liberal open license – probably hosted on CodePlex or a similar service.


Unity 1.1 Container Behavior for WCF

1 Comment »

Some time ago I needed a way to wire up an IoC container in a WCF service I was creating at that time. Since I’ve used ObjectBuilder-based containers a lot in both Composite UI Application Block and Enterprise Library, I wanted to take a closer look at the Unity container and the 2.0 version of ObjectBuilder.

To manage the creation of service instances, you have to implement the IInstanceProvider interface, and wire up the concrete type in a service behavior.

The code should be fairly documented, and a simple xUnit.NET test project is included. If you want to check out xUnit.NET, check out its CodePlex site.

I’ve put the code on a new resource page on code.msdn.microsoft.com that I have created WCF Resources. You can find the release here.