0

I have an abstract class RequestScopeContainer which acts as a temporary data holder for the current request.

public abstract class RequestScopeContainer
{

}

Is possible to tell Ninject to bind any classes that implements the abstract RequestScopeContainer class to have the life cycle as Request Scope?

Catalin
  • 11,503
  • 19
  • 74
  • 147
  • How do you register those "classes that implements the abstract RequestScopeContainer"? – Steven Feb 19 '14 at 13:50
  • You mean in `Ninject`? i was looking for something like this: `kernel.Bind().InRequestScope();`, but i need to specify a class which implements the abstract `RequestScopeContainer`. – Catalin Feb 19 '14 at 14:22

1 Answers1

1

Sure, use the ninject conventions extension: https://github.com/ninject/ninject.extensions.conventions

IBindingRoot.Bind(x => x
    .FromThisAssembly()
    .IncludingNonePublicTypes()
    .SelectAllClasses()
    .InheritedFrom<AbstractRequestScopeContainer>()
    .BindToSelf()
    .Configure(x => x.InRequestScope()));
BatteryBackupUnit
  • 12,934
  • 1
  • 42
  • 68