Created
June 24, 2014 07:46
-
-
Save Aaronontheweb/0a861d9a7a4bd9f62046 to your computer and use it in GitHub Desktop.
NinjectProps - Ninject Dependency Injection for Akka.NET actors
This file contains 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
/// <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