Replace Obsolete AllTypes class in Castle Windsor
Asked Answered
L

2

8

I have this code from old castle:

IoC.Container.Register( 
    AllTypes
        .FromAssemblyNamed(a)
        .Pick().WithService.FirstInterface()
        .Configure(o => o.LifeStyle.PerWebRequest));

When I upgrade to castle 3.2 I get this error:

Castle.MicroKernel.Registration.AllTypes' is obsolete

And this error for o.LifeStyle.PerWebRequest :

Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

How can I fix this?

Less answered 26/4, 2013 at 8:29 Comment(0)
G
12

Like @charleh said, AllTypes was replaced with Classes so fixing this problem is a simple find and replace.

Actually if you look at the compiler warning it should say:

'AllTypes' has been deprecated and will be removed in future releases. Use 'Classes' static class (if you want to just register concrete classes) or 'Types' static class (if you want to register interfaces or abstract classes too) instead. It exposes exactly the same methods.

The reason for this change was that AllTypes was a lie - it was only matching concrete (non-abstract) classes, so Classes is a much better name that better tells you what it really does.

As for the other problem, changing the property call to a method call will fix it:

Container.Register(
    Classes.FromAssemblyNamed(a)
        .Pick().WithServiceFirstInterface()
        .Configure( o => o.LifestylePerWebRequest()));

Or simpler yet, skipping the Configure:

Container.Register(
    Classes.FromAssemblyNamed(a)
        .Pick().WithServiceFirstInterface()
        .LifestylePerWebRequest());

Windsor ships with BreakingChanges.txt file which describes breaking changes and how to upgrade.

Godderd answered 27/4, 2013 at 8:16 Comment(0)
V
0

The first issue is that AllTypes is equivalent to Classes (I actually learned this this morning!)

So instead of

IoC.Container.Register(AllTypes.etc)

Use

IoC.Container.Register(Classes.etc)

Not sure about the other but quick bit of searching seems to suggest that the lifestyles are pluggable in 3.2, you may be missing a reference

Edit:

Ah: Looks like you have referenced the client build of Castle.Windsor dll - there's another build against the full .NET profile which contains the type you need - check your references

PerWebRequest Lifestyle missing in Castle Windsor 3.2

Vagal answered 26/4, 2013 at 10:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.