Archive for the ‘Castle’ Category

Castle Windsor 3.0 is released

Friday, December 16th, 2011

Castle Windsor

After suc­cess­ful beta and RC releases final ver­sion of Cas­tle Wind­sor (as well as Cas­tle Core, and a whole set of facil­i­ties) has now been released. There are no major changes between final ver­sion and RC. The dif­fer­ence is some minor bug fixes, improved excep­tion mes­sages and some small improve­ments all over the place.

 

The pack­ages are avail­able now, on Nuget (with sym­bols), and via stan­dard .zip down­load.

 

Last but not least — thank you to every­one who down­loaded beta and release can­di­date and pro­vided feed­back. You guys rock.

Getting closer… Castle Windsor 3 RC 1

Sunday, November 20th, 2011

Few weeks later than orig­i­nally expected but here it is – Cas­tle Wind­sor 3.0 (along with its facil­i­ties and Castle.Core) achieved release can­di­date status.

There is one major new fea­ture in this release: reg­is­tra­tion API gained abil­ity to spec­ify prop­er­ties to ignore/require. There are some sce­nar­ios where that’s use­ful, for exam­ple where inte­grat­ing with some 3rd party frame­work that forces you to inherit from a base class which exposes its depen­den­cies as prop­er­ties. Cre­at­ing pass-through con­struc­tors for each inher­ited class can be mun­dane. In those cases you can sim­ply mark those base class prop­er­ties as required, in which case Wind­sor will not allow them to be resolved unless all base prop­erty depen­den­cies are sat­is­fied. Prop­er­ty­Fil­ter enum sup­ports sev­eral other most com­mon sce­nar­ios, and for advanced cases there’s an over­load that gives you more control.

Container.Register(
    Classes.FromThisAssembly()
        .BasedOn<ICommon>()
        .Configure(c => c.Properties(PropertyFilter.RequireBase)));

To address per­for­mance hit at startup Wind­sor no longer enables per­for­mance coun­ters by default. Now, you have to do it explicitly:

var container = new WindsorContainer();
var diagnostic = LifecycledComponentsReleasePolicy.GetTrackedComponentsDiagnostic(container.Kernel);
var counter = LifecycledComponentsReleasePolicy.GetTrackedComponentsPerformanceCounter(new PerformanceMetricsFactory());
container.Kernel.ReleasePolicy = new LifecycledComponentsReleasePolicy(diagnostic, counter);

Full changelog is included in the pack­ages. Please, if pos­si­ble, take the time to upgrade to this ver­sion and if you find any issues report them so that the final release is rock solid. If no major issues are found, the final release will be pub­lished in two weeks.

The bina­ries are avail­able on Nuget right now, and soon on our web­site.

Windsor 3 beta 1 – dozen of Nuget packages and SymbolSource.org support

Sunday, September 4th, 2011

As promised, I released Nuget pack­ages for beta 1 of Wind­sor 3. This is my first major roll­out of Nuget pack­ages, so please report any issues work­ing with them.

Nuget and beta packages

Nuget is quickly evolv­ing and get­ting more use­ful with each release. How­ever one fea­ture it’s miss­ing right now is sup­port for pre-release pack­ages (this is com­ing in the next ver­sion).

davidebbo

This is not really a big deal, how­ever it means there are a few things you should be aware of.

Rec­om­mended version

Since the new pack­age is a pre-release, while I would really like for every­one to start using it imme­di­ately and report all issues they find, I quite under­stand that many peo­ple will rather pre­fer to stick to the last offi­cial ver­sion for the time being. To accom­mo­date that the new pack­ages are not made rec­om­mended ver­sions, so your Nuget explorer will still point to the last sta­ble (2.5.3) ver­sion if you search for Wind­sor, Castle.Core or any other pre-existing package.

nuget_explorer 

If you go to com­mand line and install one of the pack­ages with­out spec­i­fy­ing ver­sion num­ber, it will install the lat­est, that is beta 1 version.

nuget_commandline

SymbolSource.org and debug­ging into Windsor

Folks at SymbolSource.org added recently sup­port for Nuget (and Open­Wrap as well) and the new Cas­tle pack­ages take advan­tage of that. What it gives you, is you can now eas­ily debug into Windsor’s code, just like .NET frame­work ref­er­ence source (there’s a sim­ple guide at Sym­bol­Source on how to do it).

After you’re all set you can step into any of Cas­tle meth­ods in your debug­ger and watch the magic hap­pen. Very cool thing, even if I say so myself.

windsor-source-debugging

 

List of packages

Here’s the full list of v3 beta 1 pack­ages (notice those are not all Cas­tle pack­ages, just those that were pub­lished as v3 beta 1 roll­out of Windsor):

 

I hope this will make it eas­ier for every­one to test drive Wind­sor. And if you find any issues, have any sug­ges­tions or ideas, do not hes­i­tate to bring them up, either on our google group, or issue tracker.

What's new in Windsor 3: Container debugger diagnostics improvements

Monday, April 25th, 2011

As we're near­ing the release date of Cas­tle Wind­sor 3.0 (code­name Wawel) I will be blog­ging about some of the new fea­tures and improve­ments intro­duced in the new version.

In the pre­vi­ous post I intro­duced one new diag­nos­tic, and in this post we’ll explore other improve­ments in this area.

Overview

In the screen­shot below (and all other) the upper win­dow is Wind­sor 2.5, lower win­dow is Wind­sor 3. All screen­shots were taken run­ning one of open source applications.

image

As you can see there are some addi­tional diag­nos­tics present in the new ver­sion. Alto­gether the num­ber rose from 4 in pre­vi­ous ver­sion to 7 in Wawel (you’re not see­ing all of them in the screen­shots above because some of them only acti­vate if they have some­thing to show). The new ones are:

  • Default com­po­nent per ser­vice – if you have mul­ti­ple com­po­nents expos­ing one ser­vice this will show you which one of them is the default (that is which one will be used pri­mar­ily to sat­isfy depen­den­cies of that type).
  • Poten­tial Ser­vice Loca­tor usage was dis­cussed pre­vi­ously

Objects tracked by release policy

image

This one is pretty self explana­tory. It shows you all objects tracked by release pol­icy in your con­tainer, grouped by com­po­nent. Do not under­es­ti­mate the value of it. This is a fan­tas­tic tool for locat­ing objects with mis­man­aged life­time (in other words – objects that should have been released but weren’t). If you see a num­ber next to any of your com­po­nents is sus­pi­ciously high or ris­ing you may have just dis­cov­ered a flaw in life­time man­age­ment in your app.

It is worth not­ing that there were some sig­nif­i­cant changes around release poli­cies in Wind­sor 3 and what is tracked by the pol­icy has changed as well. Those changes will be cov­ered in a future post.

Com­po­nents view

Most of the debug­ger views deals with show­ing com­po­nents and there are some improve­ments in this area. Let’s go through most notable of them.

image

  • Top level view no longer shows a sequence num­ber as “Name”. The num­ber had no real mean­ing and we’re show­ing instead a much more impor­tant infor­ma­tion – lifestyle of the component.
  • If lifestyle was not set explic­itly (and Wind­sor falls back to its default for it) there will be an addi­tional star (*) next to the lifestyle, like the “Now” com­po­nent on the screenshot.
  • How we dis­play the com­po­nent was also greatly sim­pli­fied to make it much more readable.
    • We’re not show­ing the name Windsor’s using for the com­po­nent, unless you explic­itly set it. Oth­er­wise it’s just noise.
    • We’re show­ing C#-ified names of types so that they are much eas­ier to read.
    • To show open generic ser­vices we put dots (·) around generic para­me­ters, so that they stand out from nor­mal types.

Sev­eral other more minor improve­ments were intro­duced as well, but I won’t go into too much detail here.

Access­ing diag­nos­tics in code

Ever since the fea­ture was intro­duced there were requests to pro­vide pro­gram­ma­ble access to those diag­nos­tics. It is now pos­si­ble. Thanks to changes in inter­nal infra­struc­ture you can use new IDi­ag­nos­tic<> inter­face (and it’s subin­ter­faces) to write code like this:

var host = Container.Kernel.GetSubSystem(SubSystemConstants.DiagnosticsKey) as IDiagnosticsHost;
var diagnostic = host.GetDiagnostic<IUsingContainerAsServiceLocatorDiagnostic>();
var serviceLocators = diagnostic.Inspect();
Assert.IsEmpty(serviceLocators);

I hope you’ll find all of those improve­ments useful.

What's new in Windsor 3: Service Locator usage detection

Sunday, April 24th, 2011

As we're near­ing the release date of Cas­tle Wind­sor 3.0 (code­name Wawel) I will be blog­ging about some of the new fea­tures and improve­ments intro­duced in the new version.

One of the fea­tures that were intro­duced in cur­rent ver­sion 2.5 was sup­port for debug­ger diag­nos­tic views in Windsor.

In Wawel one of the improve­ments is addi­tion of a new diag­nos­tic — detec­tion of cases where the con­tainer is being used as Ser­vice Loca­tor. For those unfa­mil­iar with what Ser­vice Loca­tor is, it's an approach that breaks the basic rule of Inver­sion of Con­trol, by explic­itly call­ing out to the con­tainer from within application.

Here's where I tell you Ser­vice Loca­tor is bad

I spent last two days read­ing through the Stack­Over­flow archive of IoC related ques­tions and one of the most com­mon sources of prob­lems is that con­tainer is being used as Ser­vice Locator.

I wrote why Ser­vice Loca­tor (par­tic­u­larly when imple­mented via IoC con­tainer) is a bad idea on few occa­sions (for exam­ple here). Also Mark has a good overview of draw­backs of this approach so I won't rehash it again.

Good news is — even if some­one from your team starts using the con­tainer as Ser­vice Loca­tor, Wind­sor will now help you detect those cases.

Here's where I give you an example

Take a look at the fol­low­ing class:

[Singleton]
public class ComponentFactory
{
    private readonly IKernel kernel;

    public ComponentFactory(IKernel kernel)
    {
        this.kernel = kernel;
    }

    public object Create(String name)
    {
        return kernel.Resolve<object>(name);
    }
}

It is part of the appli­ca­tion layer (and not infra­struc­ture layer) and as such it should not be aware of the con­tainer, yet it depends on IKer­nel. Also quick look at its Cre­ate method is enough to see that it most likely is passed around through­out the appli­ca­tion and used to pull com­po­nents from the con­tainer with­out giv­ing it much thought, which as you're surely guess­ing by now is a recipe for trouble.

Here's where I show you how it looks

If you nav­i­gate in debug mode to a con­tainer instance where com­po­nents like the one described above exists a new entry in the debug­ger view will appear list­ing those components.

sl-detection

Here's where I tell you how it works

Wind­sor doesn't have the whole pic­ture of your appli­ca­tion, so it can only detect a sub­set of cases of Ser­vice Loca­tor usage. In par­tic­u­lar it is unable to detect the case when a Ser­vice Loca­tor is built com­pletely on top of the con­tainer as com­monly found, where con­tainer is assigned to a pub­lic field of a sta­tic class and accessed through that field.

Since Wind­sor only knows about the com­po­nents you reg­is­ter with it, it looks for com­po­nents that depend on the con­tainer and are not extend­ing infra­struc­ture of the con­tainer itself (like for exam­ple Inter­cep­tors are). All such com­po­nents are flagged as poten­tial ser­vice loca­tor and pre­sented to you.

I hope you'll find this fea­ture useful.

Here's where you tell me what you think

Windsor’s longest exception message just got longer

Wednesday, February 16th, 2011

exception

just one of the nice improve­ments we’re cook­ing for the next ver­sion (code­name “Wawel”).

Castle Windsor/Core 2.5.2

Monday, November 15th, 2010

New Windsor logo

Today we released sec­ond bug­fix release for Wind­sor 2.5 and for Core 2.5 (incl. Dynam­icProxy, which is what prob­a­bly is the most inter­est­ing to peo­ple). This time there are no new fea­tures, only fixes to issues iden­ti­fied since the last release (you can see the entire list in changes.txt). We have how­ever updated to NLog 2, and since it works in Sil­verlight, this release also has Log­ging Facil­ity for Sil­verlight. This is very likely the last release in 2.5 branch, and all devel­op­ment now moves to vNext.

One thing you may notice, is that while file num­ber was bumped to 2.5.2, assem­bly ver­sion still shows 2.5.1. This was requested by sev­eral users who didn’t want to have to recom­pile all third party depen­den­cies using Wind­sor 2.5.1 again, in order to use the new version.

If you’re in such sit­u­a­tion, you may drop and replace older assem­blies with the new ones, and in 99% of cases you should be just fine. How­ever in order to fix some issues, there were few break­ing changes, so if the other projects you’re using were depend­ing on the changed code you will have to upgrade them to ver­sion com­pat­i­ble with Wind­sor 2.5.2 anyway.

New logo

One more note­wor­thy devel­op­ment in Cas­tle land, as you may have noticed if you vis­ited Cas­tle Project web­site recently is that we have a new logo (or rather – set of logos) cre­ated by my very tal­ented wife.

Now back to me – the down­loads are here (Wind­sor and Core) and here (just Core) – enjoy. I am on a horse.

Point point one release for Windsor and Castle.Core

Tuesday, September 21st, 2010

Exactly one month after release 2.5.0 we released first minor update to this release for Wind­sor and Castle.Core. It con­tains some minor improve­ments and fixes for issues that were iden­ti­fied after the 2.5 release. Com­plete changelog for Wind­sor con­tains 20 items, and 9 for Castle.Core, includ­ing sin­gle break­ing change, which is dele­tion of web log­ger so that Castle.Core has no depen­dency on System.Web and we no longer need to pro­vide two ver­sions for .NET 4 (one with Client pro­file sup­port, and one with full profile).

There’s one rel­a­tively major fea­ture in the release that you should be aware of – debug­ger views in Wind­sor were extended with detec­tion of poten­tial lifestyle mis­matches. When you step over your con­fig­ured con­tainer in the debug­ger the fol­low­ing item may now appear in the list:

mismatches

This lets you detect sit­u­a­tions where you have a sin­gle­ton com­po­nent that depends on a tran­sient or per-web-request com­po­nent, which is usu­ally a bug (although there are rare cases when sin­gle­ton depend­ing on tran­sient is a valid solution).

In addi­tion to the list, the Descrip­tion will give you… well – descrip­tion of the situation:

mismatches_text

Notice that this is only a helper and due to dynamic nature of Wind­sor it can only detect a sta­t­i­cally known sub­set of pos­si­ble depen­den­cies. As such you should not assume that if the fea­ture does not detect any issues there aren’t any.

You can down­load the projects from Source­forge as usual:

Must I release everything when using Windsor?

Friday, August 27th, 2010

This is a fol­low up to my pre­vi­ous post. If you haven’t yet – go and read that one first. I’ll wait.

So where were we? Aha…

In the last post I said, that Wind­sor (any con­tainer in gen­eral) cre­ates objects for you, hence it owns them, ergo its respon­si­bil­ity is to prop­erly end their life­time when they’re no longer needed.

Since as I men­tioned in my pre­vi­ous post, Wind­sor will track your com­po­nent, it’s a com­mon mis­con­cep­tion held by users that in order to prop­erly release all com­po­nents they must call Release method on the container.

container.Release(myComponent);

How will Wind­sor know I no longer need an object?

That’s the most impor­tant part of this post really, so pay attention.

In Wind­sor (every con­tainer in gen­eral) every com­po­nent has a lifestyle asso­ci­ated with it. In short lifestyle defines the con­text in which an instance should be reused. If you want to have just sin­gle instance of a com­po­nent in the con­text of the con­tainer, you give the object a sin­gle­ton lifestyle (which is the default in Wind­sor). If you want to reuse your object in the con­text of a web request, you give it a lifestyle of a per-web-request and so on. Now the word con­text (though over­loaded) is impor­tant here.

When the con­text ends?

While some con­texts, like web request have a well defined ends that Wind­sor can detect, that’s not the case for every of them. This brings us to the Release method.

Wind­sor has a Release method that you use to explic­itly tell it “hey, I’m not gonna use this this object any­more.” Although the method is named very imper­a­tively, which would sug­gest it takes imme­di­ate action, it’s not often the case. Quite a lot of time may pass between you call the method and Wind­sor will get the object destroyed. When the object gets really destroyed is up to its lifestyle man­ager, and they act differently.

  • Sin­gle­ton will ignore your call to Release because the instance is global in the scope of the con­tainer that cre­ated it, and the fact that you don’t need the object in one place does not mean you won’t need it moments later some­where else. The scope of the sin­gle­ton lifestyle has a well defined end. Wind­sor will destroy the sin­gle­tons when the con­tainer itself is being dis­posed. This also means that you don’t have to Release your sin­gle­tons – dis­pos­ing of the con­tainer will take care of that.
  • Per-web-request will ignore your call to Release for sim­i­lar rea­sons – the object is global in the scope of a web-request. Web request also has a well defined end, so it will wait with destroy­ing the object till the end of the web request and then do all the work nec­es­sary. This also means that you don’t have to release your per-web-request com­po­nents – Wind­sor can detect end of a web request and release the per-web-request com­po­nents with­out and inter­ven­tion from your side.
  • Per-thread is like sin­gle­ton in the scope of a thread. Releas­ing Per-thread com­po­nents does noth­ing, they will be released when the con­tainer is dis­posed. This means that in this case as well you don’t have to do any­thing explic­itly about them (except for remem­ber­ing to dis­pose the con­tainer obviously) ..
  • Pooled com­po­nents are dif­fer­ent. They don’t really have a well defined “end” so you need to return a com­po­nent to the pool explic­itly (that is pass them to container’s Release method), and Wind­sor (depend­ing on the com­po­nent and con­fig­u­ra­tion of the pool) may either return the object to the pool, recy­cle it, or destroy and let it go. Thing is — it mat­ters, and it usu­ally makes sense to return the object to the pool, as soon as pos­si­ble (think con­nec­tion pool­ing in ADO.NET).
  • Tran­sient com­po­nents are sim­i­lar to pooled, because there’s no well known end to tran­sient component’s life­time, and Wind­sor will not know if you still want to use a com­po­nent or not, unless you explic­itly tell it (by call­ing Release). Since tran­sient com­po­nents are by def­i­n­i­tion non-shared Wind­sor will imme­di­ately destroy the com­po­nent when you Release it.

And then it gets interesting

If you’re now scratch­ing your head think­ing “Does Wind­sor really puts all the bur­den of releas­ing stuff on me?” don’t despair. The real­ity is – you never have to call Release explic­itly in your appli­ca­tion code. Here’s why.

You never have to call Release…

Releas­ing a com­po­nent releases entire graph. As out­lined in pre­vi­ous sec­tion, Wind­sor can detect end of scope for com­po­nents with most life­times. In that case, if you have a per-web-request Shop­ping­Card com­po­nent that depends on tran­sient Pay­ment­Cal­cu­la­tion­Ser­vice and sin­gle­ton AuditWriter, when the request ends Wind­sor will release the shop­ping card along with both of its depen­den­cies. Since auditwriter is a sin­gle­ton releas­ing it will not have any effect (which is what we want) but the tran­sient pay­ment cal­cu­la­tor will be releases with­out you hav­ing to do any­thing explicitly.

You obvi­ously need to struc­ture your appli­ca­tion prop­erly for this to work. If you’re abus­ing the con­tainer as ser­vice loca­tor than you’re cut­ting a branch you’re sit­ting on.

Explic­itly…

This also works with typed fac­to­ries – when a fac­tory is released, all the com­po­nents that you pulled via the fac­tory will be released as well. How­ever you need to be cau­tious here – if you’re expect­ing to be pulling many com­po­nents dur­ing factory’s life­time (espe­cially if the fac­tory is a sin­gle­ton) you may end up need­lessly hold­ing on to the com­po­nents for much too long, caus­ing a mem­ory leak.

Imag­ine you’re writ­ing a web browser, and you have a Tab­Fac­tory, that cre­ates tabs to dis­play in your browser. The fac­tory would be a sin­gle­ton in your appli­ca­tion, but the tabs it pro­duces would be tran­sient – user can open many tabs, then close them, then open some more, and close them as well. Being a web savvy per­son you prob­a­bly know first­hand how quickly mem­ory con­sump­tion in a web browser can go up so you cer­tainly don’t want to wait until you dis­pose of your con­tainer to release the fac­tory and release all the tabs it ever cre­ated, even the ones that were closed days ago.

More likely you’d want to tell Wind­sor to release your tran­sient tabs as soon as the user closes it. Easy – just make sure your Tab­Fac­tory has a releas­ing method that you call when the tab is closed. The impor­tant piece here is that you’d be call­ing a method on a fac­tory inter­face that is part of your appli­ca­tion code, not method on the con­tainer (well – ulti­mately that will be the result, but you don’t do this explicitly).

UPDATE:

As Mark pointed out in the com­ment there are cer­tain low level com­po­nents that act as fac­to­ries for the root object in our appli­ca­tion (ICon­troller­Fac­tory in MVC, IIn­stan­ce­Provider in WCF etc). If you’re not using typed fac­to­ries to pro­vide these ser­vice and imple­ment them man­u­ally pulling stuff from the con­tainer, than the other rule (dis­cussed below) applies — release any­thing you explic­itly resolve

In your appli­ca­tion code

There are places where you do need to call Release explic­itly – in code that extends or mod­i­fies the con­tainer. For exam­ple if you’re using a fac­tory method to cre­ate a com­po­nent by resolv­ing another com­po­nent first, you should release the other component.

container.Register(
   Component.For<ITaxCalculator>()
      .UsingFactoryMethod(k =>
      {
         var country = k.Resolve<ICountry>(user.CountryCode);
         var taxCalculator = country.GetTaxCalculator();
         k.ReleaseComponent(country);
         return taxCalculator;
      })
   );

This is a code you could place in one of your installers. It is com­pletely arti­fi­cial but that’s not the point. Point is, we’re using a fac­tory method to pro­vide instances of a com­po­nent (tax cal­cu­la­tor) and for this we’re using another com­po­nent (coun­try). Remem­ber the rule – You have to release any­thing you explic­itly resolve. We did resolve the coun­try, so unless we are sure that the coun­try is and always will be a sin­gle­ton or have one of the other self-releasing lifestyles, we should release it before return­ing the tax calculator.

Must Windsor track my components?

Thursday, August 19th, 2010

Prob­a­bly the sin­gle most mis­un­der­stood fea­ture of Cas­tle Wind­sor is regard­ing its life­time man­age­ment of com­po­nents. Hope­fully in this post (and the next one) I’ll be able to clear all the misconceptions.

Why is Wind­sor track­ing com­po­nents in the first place?

lifecycle_simplified

One of the core respon­si­bil­i­ties of a con­tainer is to man­age life­cy­cle of com­po­nents.  At a very high level it looks like in the pic­ture on the right. The con­tainer cre­ates the object, sets it up, then when it’s ready to go, it gives it to you, so that you can use it, and when it’s no longer needed it care­fully tears it apart and sends it to happy hunt­ing ground. Many peo­ple for­get about that last part, and indeed some con­tain­ers lack sup­port for this cru­cial ele­ment at all.

In order to be able to iden­tify objects it cre­ated and destroy them when their time has come, Wind­sor obvi­ously needs to have access to them and that’s why it keeps ref­er­ence to the objects it needs to destroy.

Destroy objects. What does that even mean?

I’ve been pretty abstract until now, let’s look at an actual (triv­i­al­ized) example .

public class UnitOfWork
{
   public void Init()
   {
      // some initialization logic...
   }
   public void Commit()
   {
      // commit or rollback the UoW
   }
}

We want to cre­ate the instance of our UnitOf­Work, then before we use it, we want to ini­tial­ize it, then use it for a while to do the work, and then when we’re done, com­mit all the work that we’ve done. Usu­ally in a web-app the life­time of the unit or work would be bound to a sin­gle web request, in a client app it could be bound to a screen.

It is container’s work to cre­ate the object. It’s container’s work to ini­tial­ize it. So that I don’t need to remem­ber to call the Init method myself. Espe­cially that within a web request (let’s stick to the web exam­ple) I can (and likely will) have mul­ti­ple com­po­nents depend­ing on my unit of work. Which one of them should call Init?

None. It’s not their job. Their job is to make use of it. Be lazy and out­source this to the con­tainer.  Which of my com­po­nents should Com­mit the unit of work? Also none.

None of my com­po­nents is respon­si­ble for the unit of work, since none of them cre­ated it. The con­tainer did, so it’s container’s job to clean up after the object when I’m done using it.

The destroy part is just it – do all the things with the com­po­nents that need to be done after the com­po­nent is no longer being used by the appli­ca­tion code, but before the object can be let go. The most com­mon exam­ple of that is the IDis­pos­able inter­face and Dis­pose method.

The rule in .NET frame­work is very sim­ple when it comes to Dis­pos­ing objects.

Dis­pose what you’ve cre­ated, when you’re done using it.

Hence clearly since the con­tainer is cre­at­ing the object it’s its respon­si­bil­ity to dis­pose of them. In Wind­sor lingo, you’d call the Init method on the UnitOf­Work a com­mis­sion con­cern and the Com­mit method a decom­mis­sion con­cern.

What if my object requires no clean up? Will Wind­sor still track it?

This is a very impor­tant ques­tion. The answer is also impor­tant. In short.

It depends.

Wind­sor by default will track objects that them­selves have any decom­mis­sion con­cerns, are pooled, or any of their depen­den­cies is tracked.

We will dis­cuss this in more details in a future post, since it is a big and impor­tant topic. In short though – you as a user of a com­po­nent should not know all these things (espe­cially that they can change), so you should treat all com­po­nents as being tracked..

What do you mean by default?

Wind­sor is very mod­u­lar and unsur­pris­ingly track­ing of com­po­nents is con­tained in a sin­gle object, called release pol­icy. The behav­ior described above is the behav­ior of default, Life­cy­cled­Com­po­nentsRe­lease­Pol­icy. Wind­sor comes also with alter­na­tive imple­men­ta­tion called NoTrack­ingRe­lease­Pol­icy which as its name implies will never ever track your com­po­nents, hence you never want to use it.

Now seri­ously – often peo­ple see that Wind­sor holds on to the com­po­nents it cre­ates as a mem­ory leak (it often is, when used inap­pro­pri­ately which I’ll talk about in the next post), and they go – Wind­sor hold­ing on to the objects causes mem­ory leaks, so lets use the NoTrack­ingRe­lease­Pol­icy and the prob­lem is solved.

This rea­son­ing is flawed, because the actual rea­son is you not using this fea­ture cor­rectly, not the fea­ture itself. By switch­ing to no track­ing, you end up out of the fry­ing pan and into the fire, since by not destroy­ing your objects prop­erly you’ll be fac­ing much more sub­tle, harder to find and poten­tially more severe in results bugs (like units of works not being com­mit­ted, hence los­ing work of your users). So in clos­ing – it’s there when you need it, but even when you thing you need it, you really don’t.