This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I'm using an IoC trying to inject repositories into my controllers (WinForm project). Is there any proper way of doing so? Ctor Dependencies on RepositoryBase<T> is giving me a hard time. Is it only me feeling rigidity when trying to expand Lightspeed base classes? I find it hard because of base classes being private / sealed (probably for licensing issues?) Thanks for the great product. |
|
|
Which IoC container are you using? I believe many containers will allow you to indicate dependencies (including constructor dependencies), so you can have the container construct your UnitOfWorkScopeBase and pass it to the RepositoryBase constructor for you (and, proceeding down the chain, have it construct the LightSpeedContext and pass that to the UnitOfWorkScopeBase constructor). Could you say more about the problems you are running up against? Thanks! |
|
|
I do something like this in StructureMap, which also lets you create a convention-base connextionstring chooser, useful for when you checkout on multiple machines:
using System; |
|
|
Thanks...it helped a lot. Actually I was targetting Windsor. So here's a Windsor implementation in case anyone is intrested :
public abstract class LightspeedFacility<T> : AbstractFacility where T : class, IUnitOfWork, new()
{ protected override void Init() { var context = CreateContext(); var scope = CreateScope(context); base.Kernel.Register(Component.For<LightSpeedContext<T>>().Instance(context)); base.Kernel.Register(Component.For<UnitOfWorkScopeBase<T>>().Instance(scope)); } protected abstract LightSpeedContext<T> CreateContext(); protected abstract UnitOfWorkScopeBase<T> CreateScope(LightSpeedContext<T> context); } and the implementation would be : public class TestLightspeedFacility : LightspeedFacility<TestUnitOfWork> { protected override LightSpeedContext<TestUnitOfWork> CreateContext() { return new LightSpeedContext<TestUnitOfWork>(); //Config your context in runtime here } protected override UnitOfWorkScopeBase<TestUnitOfWork> CreateScope(LightSpeedContext<TestUnitOfWork> context) { return new PerThreadUnitOfWorkScope<TestUnitOfWork>(context); } } |
|