private void Register()
        {
            _container.Register <IPeopleRepository, XmlPeopleRepository>();
            _container.Decorate <IPeopleRepository, CachedPeopleRepository>();
            _container.Decorate <IPeopleRepository, LogPeopleRepository>();

            _container.Register(typeof(ICache <>), typeof(Cache <>));
            _container.Register <ILogger, ConsoleLogger>();
            _container.Register <PeopleViewModel>();
            _container.Register <MainWindow>();
        }
Example #2
0
        public void LightInject()
        {
            var container = new LightInject.ServiceContainer();

            foreach (var type in _types)
            {
                container.Register(type, type);
            }

            int length = 0;

            if (Scenario == ResolveScenario.ResolveOne)
            {
                length = 1;
            }
            else if (Scenario == ResolveScenario.ResolveHalf)
            {
                length = _types.Length / 2;
            }
            else if (Scenario == ResolveScenario.ResolveAll)
            {
                length = _types.Length;
            }

            for (var i = 0; i < length; i++)
            {
                container.GetInstance(_types[i]);
            }

            container.Dispose();
        }
Example #3
0
        public void RegisterImplmentation()
        {
            // Auto register
            var odtLibraries = GetReferencingAssemblies("OnDemandTools")
                               .SelectMany(assembly => assembly.ExportedTypes)
                               .ToList();


            var profiles = odtLibraries.Where(t => t.GetTypeInfo().IsClass &&
                                              !t.GetTypeInfo().IsAbstract &&
                                              !t.GetTypeInfo().IsInterface).ToList();

            foreach (var item in profiles)
            {
                var ints = item.GetInterfaces();
                foreach (var it in ints)
                {
                    if (it.ToString().StartsWith("OnDemandTools", StringComparison.OrdinalIgnoreCase))
                    {
                        cntr.Register(it, item);
                    }
                }
            }

            // Add those that cannot be auto registered. Basically the ones outside 'OnDemandTools' namespace or
            // someother special case


            // Special initialization for StatusLibrary class
            OnDemandTools.DAL.Modules.Reporting.Library.StatusLibrary.Init((AppSettings)cntr.GetInstance(typeof(AppSettings)));
        }
        public static IFileWatcher CreateFileWatcher()
        {
            LightInject.ServiceContainer _container = new LightInject.ServiceContainer();
            _container.Register(typeof(IFileWatcher), typeof(WatcherEx));
            IFileWatcher obj = _container.GetInstance <IFileWatcher>();

            return(obj);
        }
Example #5
0
        public static IFileMonitor CreateFolderWatcher()
        {
            LightInject.ServiceContainer _container = new LightInject.ServiceContainer();
            _container.Register(typeof(IFileMonitor), typeof(FileMonitor));
            IFileMonitor obj = _container.GetInstance <IFileMonitor>();

            return(obj);
        }
Example #6
0
        public static IRuleEngine CreateInstance()
        {
            LightInject.ServiceContainer _container = new LightInject.ServiceContainer();
            _container.Register(typeof(IRuleEngine), typeof(RuleEngine));
            IRuleEngine obj = _container.GetInstance <IRuleEngine>();

            return(obj);
        }
Example #7
0
        public static ILogger CreateLogger()
        {
            LightInject.ServiceContainer _container = new LightInject.ServiceContainer();
            _container.Register(typeof(ILogger), typeof(Logger));
            ILogger obj = _container.GetInstance <ILogger>();

            return(obj);
        }
Example #8
0
        /// <summary>Registers the type mappings with the container.</summary>
        /// <param name="container">The container to configure.</param>
        public static void RegisterTypes(LightInject.ServiceContainer container)
        {
            container.Register <HttpContextBase>(c => new HttpContextWrapper(HttpContext.Current));
            container.Register <Versioning>(new PerRequestLifeTime());

            container.Register <Settings>(new PerContainerLifetime());
            container.Register <IFileSystem, FileSystem>(new PerContainerLifetime());
            container.Register <IFileWatcherService, FileWatcherService>(new PerContainerLifetime());
            container.Register <IMemoryCacheService, MemoryCacheService>(new PerContainerLifetime());
        }