Last active
January 8, 2016 16:07
-
-
Save jameshulse/81771d6b10c9a96927f0 to your computer and use it in GitHub Desktop.
DI() Resolver for Akka.NET Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestDependencyResolver : IDependencyResolver | |
{ | |
private readonly Dictionary<Type, Props> _registrations = new Dictionary<Type, Props>(); | |
public void Register<T>(Props instance) | |
{ | |
_registrations.Add(typeof(T), instance); | |
} | |
public Type GetType(string actorName) | |
{ | |
throw new NotImplementedException(); | |
} | |
public Func<ActorBase> CreateActorFactory(Type actorType) | |
{ | |
return () => Create(actorType).NewActor(); | |
} | |
public Props Create<TActor>() where TActor : ActorBase | |
{ | |
return _registrations[typeof (TActor)]; | |
} | |
public Props Create(Type actorType) | |
{ | |
return _registrations[actorType]; | |
} | |
public void Release(ActorBase actor) | |
{ | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestingWithDependencies : TestKit | |
{ | |
public TestingWithDependencies() | |
{ | |
var dependencyResolver = new TestDependencyResolver(); | |
dependencyResolver.Register<MyActor>(Props.Create<MyActor>()); | |
Sys.AddDependencyResolver(dependencyResolver); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment