mardi 6 octobre 2015

Dependency Injection (Unity): Where to RegisterTypes in Unit Test Project

Brand new to Unity and I am trying to figure out where I need to Register Types in a Visual Studio Unit Test Project (it's a project that has a ton of tests, so I am finding that it would be a good place to implement Unity for learning).

I have a base class (BaseTestClass) that all the TestClasses inherit from. This is the one where it would be lovely to have some dependency injection working, however, I don't know where a valid place would be to create the container and RegisterType(s) so that they can be auto injected.

Base Class:

public class BaseTestClass
{
    protected IApplicationContext ApplicationContext;

    public BaseTestClass(IApplicationContext appContext)
    {
        ApplicationContext = appContext;
    }
}

Derived class:

[TestClass]
public class RelationTest : BaseTestClass
{
    public RelationTest(IApplicationContext appContext) : base(appContext)
    {
        CreateNodeType();
    }
}

Aucun commentaire:

Enregistrer un commentaire