Krzysztof Kozmic's comment is on the spot, however it is possible to "cheat" by letting the value of your component lifestyle be injected by a component existing only in each codebase.
Let's say there exists an interface in your common libraries, with the following signature:
public interface ISetLifestyle
{
BasedOnDescriptor SetLifestyle(BasedOnDescriptor descriptor);
}
And an implementation in each of your specific components (ie service and web app)
// this class exists only in your webapp
public class SetLifestyleOnWebApp: ISetLifestyle
{
public BasedOnDescriptor SetLifestyle(BasedOnDescriptor descriptor)
{
return descriptor.LifestylePerWebRequest();
}
}
// this class exists only in your windows service
public class SetLifestyleOnService : ISetLifestyle
{
public BasedOnDescriptor SetLifestyle(BasedOnDescriptor descriptor)
{
return descriptor.LifestyleTransient(); // or whatever scope you need
}
}
In your common configuration, you could then start by registering the ISetLifestyle
service, and then using it to define the lifestyle of your components.
container.Register(Classes.FromAssemblyInThisApplication().BasedOn<ISetLifestyle>().WithServiceBase());
var myCustomLifestyleSetter = container.Resolve<ISetLifestyle>();
var customLifestyleRegistrations = myCustomLifestyleSetter.SetLifestyle(Classes.FromThisAssembly().Pick().WithServiceDefaultInterfaces());
container.Register(customLifestyleRegistrations);
You would need to make sure that
- each application defines a ISetLifestyle service, or that a default one can always be found
- classes with common lifestyles between applications are not passed to this method
I don't know if this is a good idea since it obscures the configuration but it answers your question