Skip to content

Instantly share code, notes, and snippets.

@jameshulse
Last active January 8, 2016 16:07
Show Gist options
  • Save jameshulse/81771d6b10c9a96927f0 to your computer and use it in GitHub Desktop.
Save jameshulse/81771d6b10c9a96927f0 to your computer and use it in GitHub Desktop.
DI() Resolver for Akka.NET Testing
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)
{
}
}
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