Esempio n. 1
0
        public static void Setup()
        {
            // Create a new container
            var resolver = ObjectResolver.Create();

            // Register interface->type map, default is transient(instantiate every request)
            resolver.Register <IWorkTaskRepository, SQLiteWorkTaskRepository>(Lifestyle.Singleton);
            resolver.Register <IWorkProcessRepository, SQLiteWorkProcessRepository>(Lifestyle.Singleton);
            resolver.Register <IClientRepository, SQLiteClientRepository>(Lifestyle.Singleton);
            resolver.Register <IProductRepository, SQLiteProductRepository>(Lifestyle.Singleton);
            resolver.Register <IWorkingTimeRangeRepository, SQLiteWorkingTimeRangeRepository>(Lifestyle.Singleton);
            resolver.Register <IDailyWorkRecordQueryService, SQLiteDailyWorkRecordQueryService>(Lifestyle.Singleton);
            resolver.Register <IWorkingTimeQueryService, SQLiteWorkingTimeQueryService>(Lifestyle.Singleton);
            resolver.Register <IWorkTaskWithTimesQueryService, SQLiteWorkTaskWithTimesQueryService>(Lifestyle.Singleton);
            resolver.Register <IHealthChecker, SQLiteHealthChecker>(Lifestyle.Singleton);
            resolver.Register <IScheduledEventRepository, GoogleApiScheduledEventRepository>(Lifestyle.Singleton);
            resolver.Register <IConfigurationRepository, SQLiteConfigurationRepository>(Lifestyle.Singleton);
            resolver.Register <IWorkingHourRepository, SQLiteWorkingHoursRepository>(Lifestyle.Singleton);

            resolver.Register <IReportDriver, CsvReportDriver>(Lifestyle.Singleton);
            resolver.Register <IWorkingHourImportDriver, CsvWorkingHourImportDriver>(Lifestyle.Singleton);

            // You can configure lifestyle - Transient, Singleton or Scoped
            //resolver.Register<ILogger, MailLogger>(Lifestyle.Singleton);

            // Compile and Verify container(this is required step)
            resolver.Compile();

            Resolver = resolver;

            // Get instance from container
            //var userRepository = resolver.Resolve<IUserRepository>();
            //var logger = resolver.Resolve<ILogger>();
        }
        public void Execute_Directory_ToUnspecifiedDirectory(
            string sampleFileName,  // This argument is not for command.
            string pattern,
            string expectedResultPath)
        {
            var sample = new Sample(sampleFileName, expectedResultPath);

            sample.Initialize();

            var resolver = ObjectResolver.Create();

            resolver.Register <ICommand, CommandFromTags>(Lifestyle.Singleton);
            resolver.Register <ITagPropertyEditor, TagPropertyEditor>(Lifestyle.Singleton);
            resolver.Register <IOutput, OutputDebug>(Lifestyle.Singleton);

            resolver.Compile();

            var command = resolver.Resolve <ICommand>();

            command.Execute(sample.Directory, pattern);

            var actualFilePath = sample.GetFirstFilePath();

            sample.DeleteDirectory();

            Assert.AreEqual(sample.ExpectedFilePath, actualFilePath);
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            var resolver     = ObjectResolver.Create();
            var commandTypes = CommandUtils.GetAllCommandTypes();

            resolver.Register <ITagPropertyEditor, TagPropertyEditor>(Lifestyle.Singleton);
            resolver.Register <IOutput, OutputConsole>(Lifestyle.Singleton);
            resolver.Register <ICommandParser, CommandParser>(Lifestyle.Singleton);

            resolver.RegisterCollection <ICommand>(Lifestyle.Singleton, commandTypes);

            resolver.Compile();

            var commandParser = resolver.Resolve <ICommandParser>();

            var commandString = args[0];
            var commandArgs   = args.Skip(1).ToArray();

            var command = commandParser.Parse(commandString);

            command.Execute(commandArgs);

            Console.WriteLine("Done. Press any key to continue...");
            Console.ReadLine();
        }
        protected override object CreateContainer(Type t)
        {
            var container = ObjectResolver.Create();

            container.Register(Lifestyle.Transient, t, t);
            container.Compile();
            return(container);
        }
Esempio n. 5
0
        public void PrepareBasic()
        {
            container = ObjectResolver.Create();

            RegisterBasic(container);

            container.Compile();
        }
Esempio n. 6
0
 public PluginManager(ObjectResolver iocContainer = null)
 {
     if (iocContainer == null)
     {
         iocContainer = ObjectResolver.Create();
     }
     _container = iocContainer;
 }
Esempio n. 7
0
        public ContainerSetup()
        {
            var resolver = ObjectResolver.Create();

            resolver.Register <IFileSystem, FileSystem>();
            resolver.Register <ISettings, Settings>(Lifestyle.Singleton);

            resolver.Compile();
        }
Esempio n. 8
0
        public override void PrepareBasic()
        {
            this.resolver = ObjectResolver.Create();

            RegisterDummies(this.resolver);
            RegisterStandard(this.resolver);
            RegisterComplex(this.resolver);

            this.resolver.Compile();
        }
Esempio n. 9
0
        public void Prepare()
        {
            container = ObjectResolver.Create();


            RegisterBasic(container);
            RegisterPropertyInjection(container);
            RegisterMultiple(container);

            container.Compile();
        }
Esempio n. 10
0
        public void Setup()
        {
            _container = ObjectResolver.Create();

            MicroResolverRelated.Bind(_container);

            _container.Compile();

            MicroResolverRelated.ResolveGeneric(_container);
            MicroResolverRelated.ResolveNonGeneric(_container);
        }
Esempio n. 11
0
        public override void Prepare()
        {
            this.resolver = ObjectResolver.Create();

            RegisterDummies(this.resolver);
            RegisterStandard(this.resolver);
            RegisterComplex(this.resolver);
            RegisterPropertyInjection(this.resolver);
            RegisterMultiple(this.resolver);

            this.resolver.Compile();
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            var resolver = ObjectResolver.Create();

            resolver.Register <ILogger, Logger>();
            resolver.Register <IUser, ConstructorUser>();

            resolver.Compile();

            var user = resolver.Resolve <IUser>();

            Debug.WriteLine(user.GetName());
        }
Esempio n. 13
0
        public void Setup()
        {
            _kernel = ObjectResolver.Create();

            _kernel.Register <IA, A>(Lifestyle.Transient);
            _kernel.Register <IB, B>(Lifestyle.Transient);
            _kernel.Register <IC, C>(Lifestyle.Transient);

            _kernel.Compile();

            _kernel.Resolve <IA>();
            _kernel.Resolve <IB>();
            _kernel.Resolve <IC>();
        }
Esempio n. 14
0
        public void Setup()
        {
            _kernel = ObjectResolver.Create();

            _kernel.Register <IA, A>(Lifestyle.Singleton);
            _kernel.Register <IB, B>(Lifestyle.Singleton);
            _kernel.Register <IC, C>(Lifestyle.Singleton);

            _kernel.Compile();

            _kernel.Resolve(typeof(IA));
            _kernel.Resolve(typeof(IB));
            _kernel.Resolve(typeof(IC));
        }
Esempio n. 15
0
        public void StandardTest()
        {
            var resolver = ObjectResolver.Create();

            resolver.Register <ISingleton1, Singleton1>(Lifestyle.Singleton);
            resolver.Register <ITransient1, Transient1>(Lifestyle.Transient);
            resolver.Register <ICombined1, Combined1>(Lifestyle.Transient);
            resolver.Register <IFirstService, FirstService>(Lifestyle.Singleton);
            resolver.Register <ISecondService, SecondService>(Lifestyle.Singleton);
            resolver.Register <IThirdService, ThirdService>(Lifestyle.Singleton);
            resolver.Register <ISubObjectOne, SubObjectOne>(Lifestyle.Transient);
            resolver.Register <ISubObjectTwo, SubObjectTwo>(Lifestyle.Transient);
            resolver.Register <ISubObjectThree, SubObjectThree>(Lifestyle.Transient);
            resolver.Register <IComplex1, Complex1>(Lifestyle.Transient);
            resolver.Compile();

            var v1 = resolver.Resolve <ISingleton1>() as Singleton1;

            v1.PublicField.IsNotNull();
            v1.PublicProperty.IsNotNull();
            v1.GetPrivateField().IsNotNull();
            v1.GetPrivateProperty().IsNotNull();
            v1.fromConstructor1.IsNotNull();
            v1.fromConstructor2.IsNotNull();
            v1.VerifyOkay();

            var v2 = resolver.Resolve <ISingleton1>();

            Object.ReferenceEquals(v1, v2).IsTrue();

            var f1 = resolver.Resolve <IFirstService>();

            Object.ReferenceEquals(v1.GetPrivateField(), f1).IsTrue();

            var t1 = resolver.Resolve <ITransient1>() as Transient1;
            var t2 = resolver.Resolve <ITransient1>();

            Object.ReferenceEquals(t1, t2).IsFalse();

            t1.PublicField.IsNotNull();
            t1.PublicProperty.IsNotNull();
            t1.GetPrivateField().IsNotNull();
            t1.GetPrivateProperty().IsNotNull();
            t1.fromConstructor1.IsNotNull();
            t1.fromConstructor2.IsNotNull();
            t1.VerifyOkay();
        }
Esempio n. 16
0
        public void NonGenericTest()
        {
            var resolver = ObjectResolver.Create();

            resolver.Register <ISingleton1, Singleton1>(Lifestyle.Singleton);
            resolver.Register <ITransient1, Transient1>(Lifestyle.Transient);
            resolver.Register <ICombined1, Combined1>(Lifestyle.Transient);
            resolver.Register <IFirstService, FirstService>(Lifestyle.Singleton);
            resolver.Register <ISecondService, SecondService>(Lifestyle.Singleton);
            resolver.Register <IThirdService, ThirdService>(Lifestyle.Singleton);
            resolver.Register <ISubObjectOne, SubObjectOne>(Lifestyle.Transient);
            resolver.Register <ISubObjectTwo, SubObjectTwo>(Lifestyle.Transient);
            resolver.Register <ISubObjectThree, SubObjectThree>(Lifestyle.Transient);
            resolver.Register <IComplex1, Complex1>(Lifestyle.Transient);
            resolver.RegisterCollection <IForCollection>(Lifestyle.Transient, typeof(Collection1), typeof(Collection2), typeof(Collection3));
            resolver.Compile();

            resolver.Resolve(typeof(ISingleton1)).IsInstanceOf <Singleton1>();
            resolver.Resolve(typeof(ITransient1)).IsInstanceOf <Transient1>();
            resolver.Resolve(typeof(ICombined1)).IsInstanceOf <Combined1>();
            resolver.Resolve(typeof(IFirstService)).IsInstanceOf <FirstService>();
            resolver.Resolve(typeof(ISecondService)).IsInstanceOf <SecondService>();
            resolver.Resolve(typeof(IThirdService)).IsInstanceOf <ThirdService>();
            resolver.Resolve(typeof(ISubObjectOne)).IsInstanceOf <SubObjectOne>();
            resolver.Resolve(typeof(ISubObjectTwo)).IsInstanceOf <SubObjectTwo>();
            resolver.Resolve(typeof(ISubObjectThree)).IsInstanceOf <SubObjectThree>();
            resolver.Resolve(typeof(IComplex1)).IsInstanceOf <Complex1>();

            var collection1 = (IForCollection[])resolver.Resolve(typeof(IEnumerable <IForCollection>));

            collection1[0].IsInstanceOf <Collection1>();
            collection1[1].IsInstanceOf <Collection2>();
            collection1[2].IsInstanceOf <Collection3>();

            var collection2 = (IForCollection[])resolver.Resolve(typeof(IForCollection[]));

            collection2[0].IsInstanceOf <Collection1>();
            collection2[1].IsInstanceOf <Collection2>();
            collection2[2].IsInstanceOf <Collection3>();

            var collection3 = (IForCollection[])resolver.Resolve(typeof(IReadOnlyList <IForCollection>));

            collection3[0].IsInstanceOf <Collection1>();
            collection3[1].IsInstanceOf <Collection2>();
            collection3[2].IsInstanceOf <Collection3>();
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            var t    = typeof(Program);
            var huga = t.GetHashCode();

            var t2  = typeof(IInterface);
            var aaa = t == t2;

            var resolver = ObjectResolver.Create();

            //resolver.Register<IInterface, DummyClass>(Lifestyle.Singleton);
            //resolver.Register<Moge, Moge>(Lifestyle.Transient);

            //resolver.Register<ISingleton1, Singleton1>(Lifestyle.Singleton);
            //resolver.Register<ITransient1, Transient1>(Lifestyle.Transient);
            //resolver.Register<ICombined1, Combined1>(Lifestyle.Transient);

            resolver.Register <IFirstService, FirstService>(Lifestyle.Singleton);
            //resolver.Register<ISecondService, SecondService>(Lifestyle.Singleton);
            //resolver.Register<IThirdService, ThirdService>(Lifestyle.Singleton);
            //resolver.Register<ISubObjectOne, SubObjectOne>(Lifestyle.Transient);
            //resolver.Register<ISubObjectTwo, SubObjectTwo>(Lifestyle.Transient);
            //resolver.Register<ISubObjectThree, SubObjectThree>(Lifestyle.Transient);

            //resolver.Register<IComplex1, Complex1>(Lifestyle.Transient);

            //resolver.RegisterCollection<IForCollection>(Lifestyle.Transient, typeof(Collection1), typeof(Collection2), typeof(Collection3));

            //var verify = resolver.DebuggingCompile();
            //Verify(verify);


            resolver.Compile();

            //var test = resolver.Resolve<ICombined1>();
            //Console.WriteLine(test);
        }
Esempio n. 18
0
        public void ScopeTest()
        {
            var resolver = ObjectResolver.Create();

            resolver.Register <IFirstService, FirstService>(Lifestyle.Singleton);
            resolver.Register <ISecondService, SecondService>(Lifestyle.Transient);
            resolver.Register <IThirdService, ThirdService>(Lifestyle.Scoped);
            resolver.Compile();


            IThirdService sc1 = null;
            IThirdService sc2 = null;
            IThirdService sc3 = null;
            IThirdService sc4 = null;

            {
                using (var coResolver = resolver.BeginScope(ScopeProvider.Standard))
                {
                    var s1 = coResolver.Resolve <IFirstService>();
                    var s2 = coResolver.Resolve <IFirstService>();

                    var t1 = coResolver.Resolve <ISecondService>();
                    var t2 = coResolver.Resolve <ISecondService>();

                    sc1 = coResolver.Resolve <IThirdService>();
                    sc2 = coResolver.Resolve <IThirdService>();

                    Object.ReferenceEquals(s1, s2).IsTrue();
                    Object.ReferenceEquals(t1, t2).IsFalse();

                    Object.ReferenceEquals(sc1, sc2).IsTrue();


                    (sc1 as ThirdService).DisposeCount.Is(0);
                }

                (sc1 as ThirdService).DisposeCount.Is(1);
                sc1 = sc2 = sc3 = sc4 = null;
            }

            {
                using (var coResolver = resolver.BeginScope(ScopeProvider.ThreadLocal))
                {
                    var t1 = new Thread(_ =>
                    {
                        sc1 = coResolver.Resolve <IThirdService>();
                        sc2 = coResolver.Resolve <IThirdService>();
                    });
                    t1.Start();

                    var t2 = new Thread(_ =>
                    {
                        sc3 = coResolver.Resolve <IThirdService>();
                        sc4 = coResolver.Resolve <IThirdService>();
                    });
                    t2.Start();

                    t1.Join();
                    t2.Join();


                    Object.ReferenceEquals(sc1, sc2).IsTrue();
                    Object.ReferenceEquals(sc3, sc4).IsTrue();

                    Object.ReferenceEquals(sc1, sc3).IsFalse();

                    (sc1 as ThirdService).DisposeCount.Is(0);
                    (sc3 as ThirdService).DisposeCount.Is(0);
                }

                (sc1 as ThirdService).DisposeCount.Is(1);
                (sc3 as ThirdService).DisposeCount.Is(1);
                sc1 = sc2 = sc3 = sc4 = null;
            }

            {
                using (var coResolver = resolver.BeginScope(ScopeProvider.AsyncLocal))
                {
                    Task.Run(async() =>
                    {
                        sc1 = coResolver.Resolve <IThirdService>();
                        sc2 = await GetAsync(coResolver);
                    }).Wait();

                    Task.Run(async() =>
                    {
                        sc3 = await GetAsync(coResolver);
                        sc4 = coResolver.Resolve <IThirdService>();
                    }).Wait();

                    Object.ReferenceEquals(sc1, sc2).IsTrue();
                    Object.ReferenceEquals(sc3, sc4).IsFalse();

                    (sc1 as ThirdService).DisposeCount.Is(0);
                    (sc3 as ThirdService).DisposeCount.Is(0);
                }

                (sc1 as ThirdService).DisposeCount.Is(1);
                (sc3 as ThirdService).DisposeCount.Is(1);
                sc1 = sc2 = sc3 = sc4 = null;
            }
        }
Esempio n. 19
0
        public void CollectionTest()
        {
            {
                var resolver = ObjectResolver.Create();
                resolver.RegisterCollection <IForCollection>(Lifestyle.Transient, typeof(Collection1), typeof(Collection2), typeof(Collection3));
                resolver.Compile();

                {
                    var collection1 = resolver.Resolve <IEnumerable <IForCollection> >() as IForCollection[];
                    collection1[0].IsInstanceOf <Collection1>();
                    collection1[1].IsInstanceOf <Collection2>();
                    collection1[2].IsInstanceOf <Collection3>();
                }
                {
                    var collection1 = resolver.Resolve <IReadOnlyList <IForCollection> >() as IForCollection[];
                    collection1[0].IsInstanceOf <Collection1>();
                    collection1[1].IsInstanceOf <Collection2>();
                    collection1[2].IsInstanceOf <Collection3>();
                }
                {
                    var collection1 = resolver.Resolve <IForCollection[]>() as IForCollection[];
                    collection1[0].IsInstanceOf <Collection1>();
                    collection1[1].IsInstanceOf <Collection2>();
                    collection1[2].IsInstanceOf <Collection3>();
                }
            }

            {
                var resolver = ObjectResolver.Create();
                resolver.RegisterCollection <IForCollection>(Lifestyle.Singleton, typeof(Collection1), typeof(Collection2), typeof(Collection3));
                resolver.Compile();

                {
                    var collection1 = resolver.Resolve <IEnumerable <IForCollection> >() as IForCollection[];
                    collection1[0].IsInstanceOf <Collection1>();
                    collection1[1].IsInstanceOf <Collection2>();
                    collection1[2].IsInstanceOf <Collection3>();

                    var collection2 = resolver.Resolve <IEnumerable <IForCollection> >() as IForCollection[];
                    (collection1 == collection2).IsTrue();
                }

                {
                    var collection1 = resolver.Resolve <IReadOnlyList <IForCollection> >() as IForCollection[];
                    collection1[0].IsInstanceOf <Collection1>();
                    collection1[1].IsInstanceOf <Collection2>();
                    collection1[2].IsInstanceOf <Collection3>();

                    var collection2 = resolver.Resolve <IReadOnlyList <IForCollection> >() as IForCollection[];
                    (collection1 == collection2).IsTrue();
                }
                {
                    var collection1 = resolver.Resolve <IForCollection[]>() as IForCollection[];
                    collection1[0].IsInstanceOf <Collection1>();
                    collection1[1].IsInstanceOf <Collection2>();
                    collection1[2].IsInstanceOf <Collection3>();

                    var collection2 = resolver.Resolve <IForCollection[]>() as IForCollection[];
                    (collection1 == collection2).IsTrue();
                }
            }
        }