Skip to content

Updated version? #1

@jmichas

Description

@jmichas

Hi, I enjoyed your old blog post about this stuff. Pretty much the same stuff that I run except I use xUnit instead of Nunit.

Do you have an updated BaseTest for newer versions of Unity?
I ran into obsoleted code and in trying to create a resettable factory I keep getting invalid cast errors. I can't seem to get my

 protected void RegisterResettableType<T>(Func<Action<Mock<T>>> onCreatedCallbackFactory) where T : class
{
    Container.RegisterFactory<T>(c => CreateMockInstance(onCreatedCallbackFactory), new ResettableFactoryLifetimeManager(Resetter));
    //RegisterResettableType<T>(new InjectionFactory(c => CreateMockInstance(onCreatedCallbackFactory)));
}

So my ResettableFactoryLifetimeManager is this

protected class ResettableFactoryLifetimeManager : IFactoryLifetimeManager
{
    private readonly LifetimeResetter _lifetimeResetter;

    public ResettableFactoryLifetimeManager(LifetimeResetter lifetimeResetter)
    {
        _lifetimeResetter = lifetimeResetter;
    }
    public LifetimeManager CreateLifetimePolicy()
    {
        return new FactoryResettableManager(_lifetimeResetter);
    }
}

I'm not sure what my FactoryResettableManager should be. I created a class that inherited LifetimeManager but I get an invalid cast when calling RegisterResettableType.

Any help would be great. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions