diff --git a/SyrupSource/Syrup/Framework/SyrupComponent.cs b/SyrupSource/Syrup/Framework/SyrupComponent.cs index c4af120..a39c236 100644 --- a/SyrupSource/Syrup/Framework/SyrupComponent.cs +++ b/SyrupSource/Syrup/Framework/SyrupComponent.cs @@ -34,7 +34,9 @@ public class SyrupComponent : MonoBehaviour { if (SyrupInjector != null) { SyrupInjector.AddSyrupModules(syrupModules); } else { - SyrupInjector = new SyrupInjector(syrupModules); + SyrupInjectorOptions syrupInjectorOptions = new(); + syrupInjectorOptions.VerboseLogging = verboseLogging; + SyrupInjector = new SyrupInjector(syrupInjectorOptions, syrupModules); } } diff --git a/SyrupSource/Syrup/Framework/SyrupInjector.cs b/SyrupSource/Syrup/Framework/SyrupInjector.cs index 75a2b19..ebbc6cd 100644 --- a/SyrupSource/Syrup/Framework/SyrupInjector.cs +++ b/SyrupSource/Syrup/Framework/SyrupInjector.cs @@ -24,8 +24,10 @@ public class SyrupInjector { //Given a param, map to all types that need it private readonly Dictionary> paramOfDependencies; + private bool verboseLogging = false; + //Dependencies that have been fully constructed - private readonly Dictionary fulfilledDependencies; + private readonly Dictionary fulfilledDependencies; public SyrupInjector(params ISyrupModule[] modules) { dependencySources = new Dictionary(); @@ -35,6 +37,16 @@ public class SyrupInjector { AddSyrupModules(modules); } + public SyrupInjector(SyrupInjectorOptions syrupInjectorOptions, params ISyrupModule[] modules) { + verboseLogging = syrupInjectorOptions.VerboseLogging; + + dependencySources = new Dictionary(); + paramOfDependencies = new Dictionary>(); + fulfilledDependencies = new Dictionary(); + + AddSyrupModules(modules); + } + internal void AddSyrupModules(params ISyrupModule[] modules) { indegreesForType = new Dictionary(); @@ -214,9 +226,16 @@ public class SyrupInjector { DependencyInfo dependencyInfo = dependencySources[namedDependency]; if (dependencyInfo.IsSingleton && fulfilledDependencies.ContainsKey(namedDependency)) { + if (verboseLogging) { + Debug.Log(string.Format("Provide singleton: {0}", namedDependency.ToString())); + } return fulfilledDependencies[namedDependency]; } - + + if (verboseLogging) { + Debug.Log(string.Format("Constructing object: {0}", namedDependency.ToString())); + } + object dependency; if (dependencyInfo.DependencySource == DependencySource.PROVIDER) { MethodInfo method = dependencyInfo.ProviderMethod; diff --git a/SyrupSource/Syrup/Framework/SyrupInjectorOptions.cs b/SyrupSource/Syrup/Framework/SyrupInjectorOptions.cs new file mode 100644 index 0000000..1c4641e --- /dev/null +++ b/SyrupSource/Syrup/Framework/SyrupInjectorOptions.cs @@ -0,0 +1,10 @@ +using System; + +/// +/// Optional options block that can be passed to the SyrupInjector +/// +public class SyrupInjectorOptions { + + public bool VerboseLogging { get; set; } + +} diff --git a/SyrupSource/Syrup/Framework/SyrupInjectorOptions.cs.meta b/SyrupSource/Syrup/Framework/SyrupInjectorOptions.cs.meta new file mode 100644 index 0000000..af940db --- /dev/null +++ b/SyrupSource/Syrup/Framework/SyrupInjectorOptions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cdf4e0bfd84ae4f7e88e43f70a1cfb69 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: