1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-28 10:51:48 +00:00
Radarr/NzbDrone.Test.Common/AutoMoq/Unity/AutoMockingContainerExtension.cs

39 lines
1.2 KiB
C#
Raw Normal View History

2013-07-19 03:47:55 +00:00
using System;
2011-10-07 06:36:04 +00:00
using System.Collections.Generic;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.ObjectBuilder;
namespace NzbDrone.Test.Common.AutoMoq.Unity
2011-10-07 06:36:04 +00:00
{
2013-04-07 22:40:13 +00:00
public class AutoMockingContainerExtension : UnityContainerExtension
2011-10-07 06:36:04 +00:00
{
private readonly IList<Type> registeredTypes = new List<Type>();
protected override void Initialize()
{
SetEventsOnContainerToTrackAllRegisteredTypes();
SetBuildingStrategyForBuildingUnregisteredTypes();
}
#region private methods
private void SetEventsOnContainerToTrackAllRegisteredTypes()
{
Context.Registering += ((sender, e) => RegisterType(e.TypeFrom));
Context.RegisteringInstance += ((sender, e) => RegisterType(e.RegisteredType));
}
private void RegisterType(Type typeToRegister)
{
registeredTypes.Add(typeToRegister);
}
private void SetBuildingStrategyForBuildingUnregisteredTypes()
{
var strategy = new AutoMockingBuilderStrategy(registeredTypes, Container);
Context.Strategies.Add(strategy, UnityBuildStage.PreCreation);
}
#endregion
}
}