dnagir
unread,Dec 23, 2010, 10:41:28 PM12/23/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ninject
I just have to add that currently I workaround it using the method
below (which might be incorporated into Inject) where I explicitly use
UnitOfWork scope:
public class UnitOfWork : ActivationBlock {
public UnitOfWork(IResolutionRoot parent) : base(parent) {
}
public override IRequest CreateRequest(Type service,
Func<IBindingMetadata, bool> constraint, IEnumerable<IParameter>
parameters, bool isOptional, bool isUnique) {
return Parent.CreateRequest(service, constraint, parameters,
isOptional, isUnique);
}
}
public static class NinjectExtensions {
public static IBindingNamedWithOrOnSyntax<T>
InUnitOfWorkScope<T>(this IBindingWhenInNamedWithOrOnSyntax<T> self) {
return self.InScope(x => self.Kernel.Get<UnitOfWork>());
}
}
Then during registration:
// The UnitOfWorkScope
kernel.Bind<UnitOfWork>().ToMethod(x => new
UnitOfWork(x.Kernel)).InRequestScope(); // In the worst-case, let it
be disposed with HttpContext
kernel.Bind<ILowLevelRepository>()
.ToMethod(x => new
LowLevelRepository(x.Kernel.Get<ISessionFactory>()))
.InUnitOfWorkScope();
And at the end of request in a web app I do
kernel.Get<UnitOfwork>().Dispose();