diff --git a/Jellyfish.Demo/Injection/InjectionModel.cs b/Jellyfish.Demo/Injection/InjectionModel.cs index c620380..d0ebf9f 100644 --- a/Jellyfish.Demo/Injection/InjectionModel.cs +++ b/Jellyfish.Demo/Injection/InjectionModel.cs @@ -4,6 +4,13 @@ namespace Jellyfish.Demo.Injection { public class InjectionModel { + private Injector Injector { get; } + + public InjectionModel() + { + Injector = new Injector(); + } + public IUser TemplateUser() { Injector.Template(() => new User()); diff --git a/Jellyfish.Tests/TestInjector.cs b/Jellyfish.Tests/TestInjector.cs index e037696..7beab11 100644 --- a/Jellyfish.Tests/TestInjector.cs +++ b/Jellyfish.Tests/TestInjector.cs @@ -7,9 +7,12 @@ namespace Jellyfish.Tests [TestClass] public class TestInjector { + private Injector Injector { get; set; } + [TestInitialize] public void Initialize() { + Injector = new Injector(); } [TestMethod] diff --git a/Jellyfish/DependencyInjection/InjectionExtensions.cs b/Jellyfish/DependencyInjection/InjectionExtensions.cs index ffcaac2..8f28bd3 100644 --- a/Jellyfish/DependencyInjection/InjectionExtensions.cs +++ b/Jellyfish/DependencyInjection/InjectionExtensions.cs @@ -11,10 +11,10 @@ public static class InjectionExtensions /// The type of the object /// A reference of the object, or null if static /// Thrown if some dependencies could not be resolved - public static void Inject(this T reference) + public static void Inject(this T reference, Injector injector) { - InjectionResolver.InjectProperties(reference); - InjectionResolver.InjectFields(reference); + InjectionResolver.InjectProperties(reference, injector); + InjectionResolver.InjectFields(reference, injector); } } } diff --git a/Jellyfish/DependencyInjection/Injector.cs b/Jellyfish/DependencyInjection/Injector.cs index 2e1e326..3786354 100644 --- a/Jellyfish/DependencyInjection/Injector.cs +++ b/Jellyfish/DependencyInjection/Injector.cs @@ -69,10 +69,9 @@ public void Bind(params object[] arguments) where TSubtype : TB /// Declare a template for the given type `` on how to initialize a variable spontaneously /// /// The type of the property or field that gets injected - /// The ``'s sub type to be used for initialization of the base /// The function to call everytime a property or field has to get initialized /// Thrown if the type `` could not be templated - public void Template(Func initializer) where TSubtype : TBase + public void Template(Func initializer) { Templates.AddOrUpdate(typeof(TBase), initializer as Func); } @@ -100,18 +99,8 @@ public void Define(TBase instance) Instances.AddOrUpdate(typeof(TBase), instance); } - /// - /// Declare a fixed variable for the given type `` to set all variables of type ` - /// ` to - /// - /// The type of the property or field that gets injected - /// The type of the value to inject the property or field with - /// The static instance to initialize all variables of type `` with - /// Thrown if the type `` could not be defined - public void Define(TSubtype instance) where TSubtype : TBase - { - Instances.AddOrUpdate(typeof(TBase), instance); - } + + /// /// Initialize the given type `` with either a templated function to call or a pre-defined instance diff --git a/Jellyfish/ViewModel.cs b/Jellyfish/ViewModel.cs index 20c4838..d6b9375 100644 --- a/Jellyfish/ViewModel.cs +++ b/Jellyfish/ViewModel.cs @@ -11,8 +11,8 @@ public abstract class ViewModel : ObservableObject { protected ViewModel() { - InjectionResolver.InjectProperties(this); - InjectionResolver.InjectFields(this); + //InjectionResolver.InjectProperties(this); + //InjectionResolver.InjectFields(this); } } } \ No newline at end of file