Skip to content

Instantly share code, notes, and snippets.

@Aaronontheweb
Created June 24, 2014 07:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aaronontheweb/0a861d9a7a4bd9f62046 to your computer and use it in GitHub Desktop.
Save Aaronontheweb/0a861d9a7a4bd9f62046 to your computer and use it in GitHub Desktop.
NinjectProps - Ninject Dependency Injection for Akka.NET actors
/// <summary>
/// Extension methods for creating <see cref="Props"/> instances that utilize Ninject
/// dependency injection.
/// </summary>
public static class NinjectProps
{
static IKernel _globalKernel;
/// <summary>
/// Sets a reference to a Ninject <seealso cref="IKernel"/> that will be used by ALL Ninject-based Props
/// </summary>
/// <param name="ninjectKernel"></param>
public static void SetKernel(IKernel ninjectKernel)
{
_globalKernel = ninjectKernel;
}
/// <summary>
/// Access to the Ninject kernel itself
/// </summary>
public static IKernel Kernel
{
get { return _globalKernel; }
}
/// <summary>
/// Creates a <seealso cref="Props"/> instance that leverages an active Ninject kernel
/// to create a new actor of <see cref="TActor"/> type.
/// </summary>
/// <returns>A fully equipped Props instance</returns>
public static Props For<TActor>(IKernel ninjectKernel = null) where TActor : ActorBase
{
return Props.Create(() => (TActor)(ninjectKernel ?? _globalKernel).Get(typeof (TActor)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment