Jun 18, 2007

Spring.NET framework

Spring.NET framework 1.1 M1 recently got ready for download.

For all of you who don't know what Spring is (as myself a week ago):
"Spring.NET is an open source application framework that makes building enterprise .NET applications easier. Providing components based on proven design patterns that can be integrated into all tiers of your application architecture, Spring helps increase development productivity and improve application quality and performance."

I was especially interested in the IoC/DI (Inversion of Control, Dependency Injection) and Expression Evaluation areas.

First I defined a contract:

public interface IModulePlugin : IDisposable


    void Initialize();

    void Execute();


    string Name { get; set; }

    int Value { get; set; }

    DateTime Date { get; set; }


and did two interface implementations (you may imagine the code). I then wrote some code to instantiate my loosely coupled modules:

// use spring

IApplicationContext ctx = ContextRegistry.GetContext();


// get "a" loosely coupled (DI/IoC) module

using (IModulePlugin aModule = (IModulePlugin)ctx.GetObject("aModule"))





// get "another" loosely coupled (DI/IoC) module

using (IModulePlugin aModule = (IModulePlugin)ctx.GetObject("anotherModule"))





// try exprission features

TimeSpan t = (TimeSpan)ExpressionEvaluator.GetValue(null, "DateTime.Today - date('13/02/1970 06:10:00')");

Console.WriteLine("My age is " + t.ToString() + " [days]");

that is configured in the app.config as follows:

<objects xmlns="http://www.springframework.net">


  <object name="anotherModule" type="Spring.Modules.ModulePlugin, Spring.Modules" singleton="false" init-method="Initialize">

    <property name="Name" value="Leder" />

    <property name="Value" value="14" />

    <property name="Date" value="13.02.1970" />



  <object name="aModule" type="Spring.Modules.AnotherModulePlugin, Spring.Modules" singleton="false"  init-method="Initialize" destroy-method="Dispose">

    <property name="Name" value="Markus" />

    <property name="Value" value="13" />

    <property name="Date" value="15.06.2007" />




Nice and no dependencies...

No comments:

Post a Comment