Question Background:
I am simply setting up a Unity container object, registering the types of the selected interface and the class that inherits it, then trying to return the implementation of it.
The code:
Unity:
namespace ABC.Tools.VersionControl
{
internal class Unity
{
internal static ITfsVcPromotionManager CreateUnityObjects()
{
var unityContainer = new UnityContainer();
unityContainer.RegisterType<ITfsVcPromotionManager, TfsVcPromotionManager>();
//****ERROR*****
return unityContainer.Resolve<ITfsVcPromotionManager>();
}
}
}
The interface - ITfsVcPromotionManager:
namespace ABC.Tools.VersionControl.TfsVersionControl
{
interface ITfsVcPromotionManager
{
void CheckoutTfsItem(IVersionControlItem tfsItem);
int CheckinTfsItem(IVersionControlItem tfsItem);
}
}
The class that inherits the above interface - TfsVcPromotionManager
namespace ABC.Tools.VersionControl.TfsVersionControl
{
internal class TfsVcPromotionManager:ITfsVcPromotionManager
{
private ITfsVcQaCheckoutWorker _checkoutWorker;
private ITfsVcQaCheckinWorker _checkInWorker;
private VersionControlServer _tfsServer;
private TfsVcCheckoutItem _checkoutItem = new TfsVcCheckoutItem();
public TfsVcPromotionManager(/*IVersionControlItem tfsItem*/ ITfsVcQaCheckoutWorker checkOutWorker, ITfsVcQaCheckinWorker checkInWorker, VersionControlServer tfsServer)
{
if (checkOutWorker == null || tfsServer == null)
{
throw new System.ArgumentException("tfsItem or tfsServer objects cannot be null");
}
_checkoutWorker = checkOutWorker;
_checkInWorker = checkInWorker;
_tfsServer = tfsServer;
}
public void CheckoutTfsItem(IVersionControlItem tfsItem)
{
if (tfsItem == null)
{
throw new System.ArgumentException("TfsItem cannot be null.");
}
_checkoutWorker.CheckoutTfsQaItem(_tfsServer);
}
public int CheckinTfsItem(IVersionControlItem tfsItem)
{
if (tfsItem == null)
{
throw new System.ArgumentException("tfsItem cannot be null.");
}
return _checkInWorker.CheckinTfsQaItem(tfsItem);
}
}
The error message:
Result Message: Test method ABCTestProject.TFStests.Check_Interface_CheckOut_Method threw exception: Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Adp.Tools.VersionControl.TfsVersionControl.ITfsVcPromotionManager", name = "(none)". Exception occurred while: while resolving. Exception is: InvalidOperationException - The current type, ABC.Tools.VersionControl.ITfsVcQaCheckoutWorker, is an interface and cannot be constructed. Are you missing a type mapping?
Can anyone tell me why this will not map correctly from the interface?