private void LoadPropertiesInContainer(LoaderProperties loaderProperty, string moduleName, string configFile) { string cacheKeyImplementation = moduleName + loaderProperty.ImplementationAsString; string cacheKeyInterface = moduleName + loaderProperty.InterfaceAsString; loaderProperty.ImplementationAsType = _CachingService.Get <Type>(cacheKeyImplementation); if (loaderProperty.ImplementationAsType == null) { loaderProperty.ImplementationAsType = Type.GetType(loaderProperty.ImplementationAsString, true); _CachingService.Insert(cacheKeyImplementation, loaderProperty.ImplementationAsType); } loaderProperty.InterfaceAsType = _CachingService.Get <Type>(cacheKeyInterface); if (loaderProperty.InterfaceAsType == null) { loaderProperty.InterfaceAsType = Type.GetType(loaderProperty.InterfaceAsString); _CachingService.Insert(cacheKeyInterface, loaderProperty.InterfaceAsType); } TypeInfo typeInfo = loaderProperty.ImplementationAsType.GetTypeInfo(); if (typeInfo.ImplementedInterfaces.Contains(loaderProperty.InterfaceAsType)) { _DependencyInjectionContainer.Add(loaderProperty.ImplementationAsType, loaderProperty.InterfaceAsType, cacheKeyImplementation); } else { throw new Exception($"Type: {loaderProperty.ImplementationAsString} doesn't implement {loaderProperty.InterfaceAsString} in {configFile}"); } }
public static IDependencyContainer SetupContainer() { var graceContainer = new DependencyInjectionContainer(); var container = new DependencyContainer(graceContainer); graceContainer.Add(block => block.ExportInstance(container).As <IDependencyContainer>()); container.RegisterCoreDependencies() .RegisterUIDependencies() .RegisterDroidDependencies(); ServiceLocater.Create(container); return(container); }
private static void RegisterLogging(DependencyInjectionContainer container) { var logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Lelve:u3}] <{SourceContext:l}> {Message:lj}{NewLine}{Exception}") .WriteTo.File( new CompactJsonFormatter(), "Logs/spnode.log", LogEventLevel.Information, rollingInterval: RollingInterval.Hour, rollOnFileSizeLimit: true, shared: true, retainedFileCountLimit: null) .CreateLogger(); Log.Logger = logger; container.Add(c => c .ExportInstance(logger) .As <ILogger>()); }
public void DependencyInjectionContainer_Add_Registration_Throws_Exception_For_Null() { var container = new DependencyInjectionContainer(); Assert.Throws <ArgumentNullException>(() => container.Add((Action <IExportRegistrationBlock>)null)); }
public void DependencyInjectionContainer_Add_Module_Throws_Exception_For_Null() { var container = new DependencyInjectionContainer(); Assert.Throws <ArgumentNullException>(() => container.Add((IConfigurationModule)null)); }
public void Register <T, TImpl>() where TImpl : T { _container.Add(block => block.Export <TImpl>().As <T>()); }
public void RegisterType(Type type) => _container.Add(type);