Exemplo n.º 1
0
        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}");
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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>());
        }
Exemplo n.º 4
0
        public void DependencyInjectionContainer_Add_Registration_Throws_Exception_For_Null()
        {
            var container = new DependencyInjectionContainer();

            Assert.Throws <ArgumentNullException>(() => container.Add((Action <IExportRegistrationBlock>)null));
        }
Exemplo n.º 5
0
        public void DependencyInjectionContainer_Add_Module_Throws_Exception_For_Null()
        {
            var container = new DependencyInjectionContainer();

            Assert.Throws <ArgumentNullException>(() => container.Add((IConfigurationModule)null));
        }
Exemplo n.º 6
0
 public void Register <T, TImpl>() where TImpl : T
 {
     _container.Add(block => block.Export <TImpl>().As <T>());
 }
Exemplo n.º 7
0
Arquivo: BitEngine.cs Projeto: e5r/bit
 public void RegisterType(Type type) => _container.Add(type);