Question

This code:

public void Install(IWindsorContainer container, IConfigurationStore store)
{
    container.Register(AllTypes.FromThisAssembly()      
                  //AllTypes.FromAssemblyNamed("Acme.Crm.Data")
                  .Where(type => type.Name.EndsWith("Repository"))
                  .WithService.DefaultInterfaces()
                  .Configure(c => c.LifeStyle.PerWebRequest));
}

...which is derived/adapted from the official docs here, is failing with, "Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement"

What have I fouled up? Or are the official docs misleading me?

UPDATE

At Simon Whitehead's request, here is the entire class:

using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Castle.MicroKernel.Lifestyle;

namespace HandheldServer.DIInstallers
{
    public class RepositoriesInstaller : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(//Classes.FromThisAssembly() 
                               //AllTypes.FromAssemblyNamed("Acme.Crm.Data")
                               AllTypes.FromThisAssembly()
                                       .Where(type => type.Name.EndsWith("Repository"))
                                       .WithService.DefaultInterfaces()
                                        //.Configure(c => c.LifeStyle.PerWebRequest));
                                       .Configure(c => c.LifeStyle.PerWebRequest));
        }
    }
}
Was it helpful?

Solution

I think it's the docs again. Configure takes an Action, which is a function which is supposed to return void, and this lambda is trying to return a value.

Use

.Configure(c => c.LifestylePerWebRequest())

or as it doesn't look like you're planning to use different lifestyles for different components you can just apply the lifestyle without using Configure:

.Where(type => type.Name.EndsWith("Repository"))
.WithService.DefaultInterfaces()
.LifestylePerWebRequest());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top