mirror of
https://github.com/Sonarr/Sonarr
synced 2024-12-26 17:57:43 +00:00
42 lines
No EOL
1.2 KiB
C#
42 lines
No EOL
1.2 KiB
C#
|
|
|
|
using System.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.Practices.Unity;
|
|
using Microsoft.Practices.Unity.ObjectBuilder;
|
|
|
|
namespace NzbDrone.Test.Common.AutoMoq.Unity
|
|
{
|
|
public class AutoMockingContainerExtension : UnityContainerExtension
|
|
{
|
|
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
|
|
}
|
|
} |