Search code examples
c#inversion-of-controlcastle

Castle Windsor FirstInterface().Configure(c=> c.LifeStyle.PerWebRequest)


I am Looking at ProDiner Sample MVC project. I updated the Castle Windsor reference to 3 from 2.

public static void RegisterAllFromAssemblies(string a)
    {
        IoC.Container.Register(
            AllTypes.FromAssemblyNamed(a).Pick().WithService
            .FirstInterface().Configure(c=> c.LifeStyle.PerWebRequest));
    }

The c.LifeStyle.PerWebRequest has a red squiggly saying

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

How do I fix this issue?


Solution

  • Some of those method calls are now marked as obsolete. This is the latest way of using the api:

    container.Register(
        Castle.MicroKernel.Registration.Classes.FromAssemblyNamed(a)
        .WithServiceFirstInterface()
        .LifestylePerWebRequest()
    );