Ejemplo n.º 1
0
 public void PrepareAndRegisterAndSimpleResolve(IContainerAdapter container)
 {
     container.PrepareBasic();
     container.Resolve(typeof(IBasicService1));
     container.Resolve(typeof(ISingleton1));
     container.Dispose();
 }
Ejemplo n.º 2
0
 public override void MethodToBenchmark(IContainerAdapter container)
 {
     container.PrepareBasic();
     container.Resolve(typeof(IDummyOne));
     container.Resolve(typeof(ISingleton1));
     container.Dispose();
 }
Ejemplo n.º 3
0
        public void SingletonLifetime(IContainerAdapter adapter)
        {
            adapter.RegisterSingleton<IService, IndependentService>();
            var instance1 = adapter.Resolve<IService>();
            var instance2 = adapter.Resolve<IService>();

            Assert.Same(instance1, instance2);
        }
Ejemplo n.º 4
0
        public void TransientLifetime(IContainerAdapter adapter)
        {
            adapter.RegisterTransient <IService, IndependentService>();
            var instance1 = adapter.Resolve <IService>();
            var instance2 = adapter.Resolve <IService>();

            Assert.NotSame(instance1, instance2);
        }
Ejemplo n.º 5
0
        public void SingletonLifetime(IContainerAdapter adapter)
        {
            adapter.RegisterSingleton <IService, IndependentService>();
            var instance1 = adapter.Resolve <IService>();
            var instance2 = adapter.Resolve <IService>();

            Assert.Same(instance1, instance2);
        }
        public override void MethodToBenchmark(IContainerAdapter container)
        {
            var result1 = (ICalculator1)container.Resolve(typeof(ICalculator1));
            var result2 = (ICalculator2)container.Resolve(typeof(ICalculator2));
            var result3 = (ICalculator3)container.Resolve(typeof(ICalculator3));

            result1.Add(5, 10);
            result2.Add(5, 10);
            result3.Add(5, 10);
        }
Ejemplo n.º 7
0
        public void InterceptorToBenchmark(IContainerAdapter container)
        {
            var result1 = (IInerceptor1)container.Resolve(typeof(IInerceptor1));
            var result2 = (IInerceptor2)container.Resolve(typeof(IInerceptor2));
            var result3 = (IInerceptor3)container.Resolve(typeof(IInerceptor3));

            result1.Concat("Hello", "Wolrd");
            result2.Concat("Hello", "Wolrd");
            result3.Concat("Hello", "Wolrd");
        }
        public void RegistrationAtAnyStage(IContainerAdapter adapter)
        {
            adapter.RegisterType <IService, IndependentService>();
            adapter.Resolve <IService>();
            adapter.RegisterType <IService2, IndependentService2>();

            var resolved = adapter.Resolve <IService2>();

            Assert.NotNull(resolved);
        }
        public override void MethodToBenchmark(IContainerAdapter container)
        {
            var result1 = (ICalculator1)container.Resolve(typeof(ICalculator1));
            var result2 = (ICalculator2)container.Resolve(typeof(ICalculator2));
            var result3 = (ICalculator3)container.Resolve(typeof(ICalculator3));

            result1.Add(5, 10);
            result2.Add(5, 10);
            result3.Add(5, 10);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Implement this method to configure your application when it starts.
        /// For exemple, you can retrieve the view factory from the container,
        /// and then retrieve a page and set it as MainPage
        /// (you will need a reference to your Application instance).
        /// </summary>
        /// <param name="container">The dependency container</param>
        private void ConfigureApplication(IContainerAdapter container)
        {
            var viewFactory = container.Resolve <IViewFactory>();
            var navigator   = container.Resolve <INavigator>();

            // Get the first page to show to the user
            var detailPage = GetFirstPage(viewFactory);

            if (detailPage == null)
            {
                throw new ArgumentException($"An instance of a Page must be returned in {GetType().FullName}.GetFirstPage()");
            }

            var detailViewModel = detailPage.BindingContext as IViewModel;

            // We might need to use a MasterDetailsPage if this method returns something
            var        masterPage      = GetMasterPage(viewFactory);
            IViewModel masterViewModel = null;

            if (masterPage != null)
            {
                masterViewModel = masterPage.BindingContext as IViewModel;
            }

            // The unit tests cannot go through this block as we don't have an application instance to test
            if (App != null)
            {
                // Navigation events, entering
                if (masterViewModel != null)
                {
                    masterViewModel.ViewEntering();
                }
                if (detailViewModel != null)
                {
                    detailViewModel.ViewEntering();
                }

                Page navPage = new PillarNavigationPage(detailPage, navigator);
                App.MainPage = masterPage == null
                    ? navPage
                    : new MasterDetailPage {
                    Master = masterPage, Detail = navPage
                };

                // Navigation events, entered
                if (masterViewModel != null)
                {
                    masterViewModel.ViewEntered();
                }
                if (detailViewModel != null)
                {
                    detailViewModel.ViewEntered();
                }
            }
        }
Ejemplo n.º 11
0
        public void LazyanBeUsedToResolveCircularDepenendency(IContainerAdapter adapter)
        {
            adapter.RegisterSingleton <ServiceWithRecursiveLazyDependency1>();
            adapter.RegisterSingleton <ServiceWithRecursiveLazyDependency2>();

            var resolved1 = adapter.Resolve <ServiceWithRecursiveLazyDependency1>();
            var resolved2 = adapter.Resolve <ServiceWithRecursiveLazyDependency2>();

            Assert.Same(resolved2, resolved1.Dependency);
            Assert.Same(resolved1, resolved2.Dependency);
        }
Ejemplo n.º 12
0
        public void RegisterSingletonFactory()
        {
            _container = new PillarDefaultIoc();

            _container.RegisterSingleton <IFoo>(() => new Foo());

            var foo1 = _container.Resolve <IFoo>();
            var foo2 = _container.Resolve <IFoo>();

            Assert.Same(foo1, foo2);
        }
Ejemplo n.º 13
0
        public void LazyanBeUsedToResolveCircularDepenendency(IContainerAdapter adapter)
        {
            adapter.RegisterSingleton<ServiceWithRecursiveLazyDependency1>();
            adapter.RegisterSingleton<ServiceWithRecursiveLazyDependency2>();

            var resolved1 = adapter.Resolve<ServiceWithRecursiveLazyDependency1>();
            var resolved2 = adapter.Resolve<ServiceWithRecursiveLazyDependency2>();

            Assert.Same(resolved2, resolved1.Dependency);
            Assert.Same(resolved1, resolved2.Dependency);
        }
        public void Run <TPresenter>() where TPresenter : class, IPresenter
        {
            if (!_container.IsRegistered <TPresenter>())
            {
                _container.Register <TPresenter>();
            }

            var presenter = _container.Resolve <TPresenter>();

            presenter.Run();
        }
Ejemplo n.º 15
0
        private static void WarmUp(IContainerAdapter container)
        {
            var interface1 = (ISingleton)container.Resolve(typeof(ISingleton));
            var interface2 = (ITransient)container.Resolve(typeof(ITransient));
            var combined   = (ICombined)container.Resolve(typeof(ICombined));

            if (container.SupportsInterception)
            {
                var calculator = (ICalculator)container.ResolveProxy(typeof(ICalculator));
                calculator.Add(1, 2);
            }
        }
        public void ReuseWithinRequest(IContainerAdapter adapter)
        {
            adapter.RegisterPerWebRequest <IndependentService>();

            BeginRequest(adapter);
            var first  = adapter.Resolve <IndependentService>();
            var second = adapter.Resolve <IndependentService>();

            EndRequest(adapter);

            Assert.Same(first, second);
        }
        protected void CanRegisterTwoFluentTypes(Func <IContainerAdapter> adapterFunc)
        {
            IContainerAdapter adapter = adapterFunc();

            var registration = adapter.CreateComponentRegistration <ComponentRegistration>()
                               .Register <IDependantClass, ISuperDependantClass>()
                               .As <DependantClass>();

            adapter.Register(registration);

            Assert.AreEqual(adapter.Resolve <IDependantClass>().GetType(), adapter.Resolve <ISuperDependantClass>().GetType());
            Assert.AreEqual(typeof(DependantClass), adapter.Resolve <ISuperDependantClass>().GetType());
            Assert.AreEqual(typeof(DependantClass), adapter.Resolve <IDependantClass>().GetType());
        }
Ejemplo n.º 18
0
        public void OpenGenericTypes(IContainerAdapter adapter)
        {
            adapter.RegisterTransient(typeof(IGenericService <>), typeof(GenericService <>));
            var resolved = adapter.Resolve <IGenericService <int> >();

            Assert.NotNull(resolved);
        }
        public void PropertyDependencyIsOptional(IContainerAdapter adapter)
        {
            adapter.RegisterType<ServiceWithSimplePropertyDependency>();
            var component = adapter.Resolve<ServiceWithSimplePropertyDependency>();

            Assert.Null(component.Service);
        }
Ejemplo n.º 20
0
        public void OpenGenericTypes(IContainerAdapter adapter)
        {
            adapter.RegisterTransient(typeof(IGenericService<>), typeof(GenericService<>));
            var resolved = adapter.Resolve<IGenericService<int>>();

            Assert.NotNull(resolved);
        }
Ejemplo n.º 21
0
        public void PropertyDependencyIsOptional(IContainerAdapter adapter)
        {
            adapter.RegisterType <ServiceWithSimplePropertyDependency>();
            var component = adapter.Resolve <ServiceWithSimplePropertyDependency>();

            Assert.Null(component.Service);
        }
        protected override void OnClick(EventArgs e)
        {
            var form   = IoCContainer.Resolve <SettingsForm>();
            var result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                // Save the stuff
                var provider = IoCContainer.Resolve <SettingsProvider>();
                provider.Save();
            }
            else
            {
                form.UndoChanges();
            }
        }
Ejemplo n.º 23
0
        public void IndependentServiceRegisteredAsSelf(IContainerAdapter adapter)
        {
            adapter.RegisterType<IndependentService>();
            var component = adapter.Resolve<IndependentService>();

            Assert.NotNull(component);
        }
Ejemplo n.º 24
0
        public void IndependentServiceRegisteredAsSelf(IContainerAdapter adapter)
        {
            adapter.RegisterType <IndependentService>();
            var component = adapter.Resolve <IndependentService>();

            Assert.NotNull(component);
        }
Ejemplo n.º 25
0
        public IStartableBus CreateBus()
        {
            FillOutMissingRegistrationsWithDefaults();

            ValidateConfiguration();

            return(containerAdapter.Resolve <IStartableBus>());
        }
Ejemplo n.º 26
0
 /// <summary>
 /// 获取指定类型的服务对象
 /// </summary>
 /// <typeparam name="TService">服务对象类型</typeparam>
 /// <returns>服务对象实例</returns>
 public static TService GetService <TService>()
 {
     if (!Container.IsRegistered <TService>())
     {
         throw new ArgumentException($"服务类型 {typeof(TService)} 未在容器中注册!");
     }
     return(Container.Resolve <TService>());
 }
        public void MissingPrimitive(IContainerAdapter adapter)
        {
            adapter.RegisterType<IService, IndependentService>();
            adapter.RegisterType<ServiceWithDependencyAndOptionalInt32Parameter>();

            var component = adapter.Resolve<ServiceWithDependencyAndOptionalInt32Parameter>();

            Assert.NotNull(component);
        }
Ejemplo n.º 28
0
        public void MissingPrimitiveDefaultValue(IContainerAdapter adapter)
        {
            adapter.RegisterType <IService, IndependentService>();
            adapter.RegisterType <ServiceWithDependencyAndOptionalInt32Parameter>();

            var component = adapter.Resolve <ServiceWithDependencyAndOptionalInt32Parameter>();

            Assert.Equal(5, component.Optional);
        }
        public void MissingPrimitiveDefaultValue(IContainerAdapter adapter)
        {
            adapter.RegisterType<IService, IndependentService>();
            adapter.RegisterType<ServiceWithDependencyAndOptionalInt32Parameter>();

            var component = adapter.Resolve<ServiceWithDependencyAndOptionalInt32Parameter>();

            Assert.Equal(5, component.Optional);
        }
Ejemplo n.º 30
0
        public void PrebuiltInstance(IContainerAdapter adapter)
        {
            var instance = new IndependentService();
            adapter.RegisterInstance<IService>(instance);

            var resolved = adapter.Resolve<IService>();

            Assert.Same(instance, resolved);
        }
Ejemplo n.º 31
0
        public void MissingPrimitive(IContainerAdapter adapter)
        {
            adapter.RegisterType <IService, IndependentService>();
            adapter.RegisterType <ServiceWithDependencyAndOptionalInt32Parameter>();

            var component = adapter.Resolve <ServiceWithDependencyAndOptionalInt32Parameter>();

            Assert.NotNull(component);
        }
Ejemplo n.º 32
0
        public void NotCreatingLazyPrematurely(IContainerAdapter adapter)
        {
            adapter.RegisterType <IService, IndependentService>();
            adapter.RegisterType <ServiceWithSimpleConstructorDependency>();

            var lazy = adapter.Resolve <Lazy <ServiceWithSimpleConstructorDependency> >();

            Assert.NotNull(lazy);
            Assert.False(lazy.IsValueCreated);
        }
Ejemplo n.º 33
0
        public void BasicLazySupport(IContainerAdapter adapter)
        {
            adapter.RegisterType <IService, IndependentService>();
            adapter.RegisterType <ServiceWithSimpleConstructorDependency>();

            var lazy = adapter.Resolve <Lazy <ServiceWithSimpleConstructorDependency> >();

            Assert.NotNull(lazy);
            Assert.NotNull(lazy.Value);
        }
Ejemplo n.º 34
0
        public void ConstructorDependencyUsingInstance(IContainerAdapter adapter)
        {
            var instance = new IndependentService();
            adapter.RegisterInstance<IService>(instance);
            adapter.RegisterType<ServiceWithSimpleConstructorDependency>();

            var dependent = adapter.Resolve<ServiceWithSimpleConstructorDependency>();

            Assert.Same(instance, dependent.Service);
        }
Ejemplo n.º 35
0
        public void NotCreatingLazyPrematurely(IContainerAdapter adapter)
        {
            adapter.RegisterType<IService, IndependentService>();
            adapter.RegisterType<ServiceWithSimpleConstructorDependency>();

            var lazy = adapter.Resolve<Lazy<ServiceWithSimpleConstructorDependency>>();

            Assert.NotNull(lazy);
            Assert.False(lazy.IsValueCreated);
        }
Ejemplo n.º 36
0
        public void BasicLazySupport(IContainerAdapter adapter)
        {
            adapter.RegisterType<IService, IndependentService>();
            adapter.RegisterType<ServiceWithSimpleConstructorDependency>();

            var lazy = adapter.Resolve<Lazy<ServiceWithSimpleConstructorDependency>>();

            Assert.NotNull(lazy);
            Assert.NotNull(lazy.Value);
        }
Ejemplo n.º 37
0
        public void ConstructorDependency(IContainerAdapter adapter)
        {
            adapter.RegisterType<IService, IndependentService>();
            adapter.RegisterType<ServiceWithSimpleConstructorDependency>();

            var component = adapter.Resolve<ServiceWithSimpleConstructorDependency>();

            Assert.NotNull(component.Service);
            Assert.IsAssignableFrom<IndependentService>(component.Service);
        }
Ejemplo n.º 38
0
        public void PrebuiltInstance(IContainerAdapter adapter)
        {
            var instance = new IndependentService();

            adapter.RegisterInstance <IService>(instance);

            var resolved = adapter.Resolve <IService>();

            Assert.Same(instance, resolved);
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Maps the control to the adapter.
        /// </summary>
        /// <typeparam name="TControl">The type of the control.</typeparam>
        /// <typeparam name="TAdapter">The type of the adapter.</typeparam>
        /// <returns>
        /// A mapper which maps the control to the adapter.
        /// </returns>
        public RegionAdapterMapper Map <TControl, TAdapter>()
            where TAdapter : class, IRegionAdapter
        {
            if (null != Mappings)
            {
                Mappings.RegisterMapping(typeof(TControl), m_Container.Resolve <TAdapter>());
            }

            return(this);
        }
Ejemplo n.º 40
0
        public void ConstructorDependency(IContainerAdapter adapter)
        {
            adapter.RegisterType <IService, IndependentService>();
            adapter.RegisterType <ServiceWithSimpleConstructorDependency>();

            var component = adapter.Resolve <ServiceWithSimpleConstructorDependency>();

            Assert.NotNull(component.Service);
            Assert.IsAssignableFrom <IndependentService>(component.Service);
        }
        public void ComponentIsDisposedAtTheEndOfRequest(IContainerAdapter adapter)
        {
            adapter.RegisterPerWebRequest<DisposableService>();

            BeginRequest(adapter);
            var service = adapter.Resolve<DisposableService>();
            EndRequest(adapter);

            Assert.True(service.Disposed);
        }
Ejemplo n.º 42
0
        public void SimpleTransients()
        {
            var foo = _container.Resolve <IFoo>();
            var bar = _container.Resolve <IBar>();

            Assert.NotNull(foo);
            Assert.NotNull(bar);
            Assert.NotNull(bar.InnerFoo);
        }
Ejemplo n.º 43
0
        private static long MeasureCombined(IContainerAdapter container)
        {
            var watch = Stopwatch.StartNew();

            for (int i = 0; i < LoopCount; i++)
            {
                container.Resolve<ICombined>();
            }

            return watch.ElapsedMilliseconds;
        }
Ejemplo n.º 44
0
        public void FactoryWithNoParameters(IContainerAdapter adapter)
        {
            adapter.RegisterType<IService, IndependentService>();
            adapter.RegisterType<ServiceWithSimpleConstructorDependency>();

            var func = adapter.Resolve<Func<ServiceWithSimpleConstructorDependency>>();

            Assert.NotNull(func);
            var result = func();
            Assert.NotNull(result);
        }
Ejemplo n.º 45
0
        public void TransientFactoryUsedBySingletonStillCreatesTransient(IContainerAdapter adapter)
        {
            adapter.RegisterTransient <IService, IndependentService>();
            adapter.RegisterSingleton <ServiceWithFuncConstructorDependency>();

            var service = adapter.Resolve <ServiceWithFuncConstructorDependency>();
            var first   = service.Factory();
            var second  = service.Factory();

            Assert.NotSame(first, second);
        }
Ejemplo n.º 46
0
        public void ConstructorDependencyUsingInstance(IContainerAdapter adapter)
        {
            var instance = new IndependentService();

            adapter.RegisterInstance <IService>(instance);
            adapter.RegisterType <ServiceWithSimpleConstructorDependency>();

            var dependent = adapter.Resolve <ServiceWithSimpleConstructorDependency>();

            Assert.Same(instance, dependent.Service);
        }
Ejemplo n.º 47
0
        public void FactoryWithParameterForSubdependency(IContainerAdapter adapter)
        {
            adapter.RegisterType<ServiceWithSimpleConstructorDependency>();
            adapter.RegisterType<ServiceWithDependencyOnServiceWithOtherDependency>();

            var service = new IndependentService();
            var func = adapter.Resolve<Func<IService, ServiceWithDependencyOnServiceWithOtherDependency>>();

            Assert.NotNull(func);
            var result = func(service);
            Assert.NotNull(result);
            Assert.Same(service, result.Service.Service);
        }
Ejemplo n.º 48
0
        public void FactoryWithParameter(IContainerAdapter adapter)
        {
            adapter.RegisterType<IService, IndependentService>();
            adapter.RegisterType<ServiceWithTwoConstructorDependencies>();
            var service2 = new IndependentService2();

            var func = adapter.Resolve<Func<IService2, ServiceWithTwoConstructorDependencies>>();

            Assert.NotNull(func);
            var result = func(service2);
            Assert.NotNull(result);
            Assert.Same(service2, result.Service2);
        }
        public void FactoryNoReuseBetweenRequests(IContainerAdapter adapter)
        {
            adapter.RegisterPerWebRequest<IService, IndependentService>();
            adapter.RegisterSingleton<ServiceWithFuncConstructorDependency>();

            var service = adapter.Resolve<ServiceWithFuncConstructorDependency>();

            BeginRequest(adapter);
            var first = service.Factory();
            EndRequest(adapter);

            BeginRequest(adapter);
            var second = service.Factory();
            EndRequest(adapter);

            Assert.NotSame(first, second);
        }
Ejemplo n.º 50
0
        private static void MeasureResolvePerformance(IContainerAdapter container, Result outputResult)
        {
            var singletonWatch = new Stopwatch();
            var transientWatch = new Stopwatch();
            var combinedWatch = new Stopwatch();
            var conditionsWatch = new Stopwatch();
            var genericWatch = new Stopwatch();
            var complexWatch = new Stopwatch();
            var multipleWatch = new Stopwatch();
            var propertyWatch = new Stopwatch();
            var childContainerWatch = new Stopwatch();

            for (int i = 0; i < LoopCount; i++)
            {
                singletonWatch.Start();
                var result1 = (ISingleton)container.Resolve(typeof(ISingleton));
                singletonWatch.Stop();

                transientWatch.Start();
                var result2 = (ITransient)container.Resolve(typeof(ITransient));
                transientWatch.Stop();

                combinedWatch.Start();
                var result3 = (ICombined)container.Resolve(typeof(ICombined));
                combinedWatch.Stop();

                complexWatch.Start();
                var complexResult = (IComplex)container.Resolve(typeof(IComplex));
                complexWatch.Stop();

                if (container.SupportsPropertyInjection)
                {
                    propertyWatch.Start();
                    var propertyInjectionResult = (IComplexPropertyObject)container.Resolve(typeof(IComplexPropertyObject));
                    propertyWatch.Stop();
                }

                if (container.SupportsConditional)
                {
                    conditionsWatch.Start();
                    var result4 = (ImportConditionObject)container.Resolve(typeof(ImportConditionObject));
                    var result5 = (ImportConditionObject2)container.Resolve(typeof(ImportConditionObject2));
                    conditionsWatch.Stop();
                }

                if (container.SupportGeneric)
                {
                    genericWatch.Start();
                    var genericResult = (ImportGeneric<int>)container.Resolve(typeof(ImportGeneric<int>));
                    genericWatch.Stop();
                }

                if (container.SupportsMultiple)
                {
                    multipleWatch.Start();
                    var importMultiple = (ImportMultiple)container.Resolve(typeof(ImportMultiple));
                    multipleWatch.Stop();
                }

                if (container.SupportsChildContainer && i < ChildContainerLoopCount)
                {
                    // Note I'm writing the test this way specifically because it matches the Per Request bootstrapper for Nance
                    // It's also a very common pattern used in MVC applications where a scope is created per request
                    childContainerWatch.Start();

                    using (var childContainer = container.CreateChildContainerAdapter())
                    {
                        childContainer.Prepare();

                        var scopedCombined = childContainer.Resolve(typeof(ICombined));
                    }

                    childContainerWatch.Stop();
                }
            }

            outputResult.SingletonTime = singletonWatch.ElapsedMilliseconds;
            outputResult.TransientTime = transientWatch.ElapsedMilliseconds;
            outputResult.CombinedTime = combinedWatch.ElapsedMilliseconds;
            outputResult.ComplexTime = complexWatch.ElapsedMilliseconds;

            if (container.SupportsPropertyInjection)
            {
                outputResult.PropertyInjectionTime = propertyWatch.ElapsedMilliseconds;
            }

            if (container.SupportGeneric)
            {
                outputResult.GenericTime = genericWatch.ElapsedMilliseconds;
            }

            if (container.SupportsMultiple)
            {
                outputResult.MultipleImport = multipleWatch.ElapsedMilliseconds;
            }

            if (container.SupportsConditional)
            {
                outputResult.ConditionalTime = conditionsWatch.ElapsedMilliseconds;
            }

            if (container.SupportsChildContainer)
            {
                outputResult.ChildContainerTime = childContainerWatch.ElapsedMilliseconds * (LoopCount / ChildContainerLoopCount);
            }
        }
 public override void MethodToBenchmark(IContainerAdapter container)
 {
     var singleton1 = (ISingleton1)container.Resolve(typeof(ISingleton1));
     var singleton2 = (ISingleton2)container.Resolve(typeof(ISingleton2));
     var singleton3 = (ISingleton3)container.Resolve(typeof(ISingleton3));
 }
 public override void MethodToBenchmark(IContainerAdapter container)
 {
     var transient1 = (ITransient1)container.Resolve(typeof(ITransient1));
     var transient2 = (ITransient2)container.Resolve(typeof(ITransient2));
     var transient3 = (ITransient3)container.Resolve(typeof(ITransient3));
 }
Ejemplo n.º 53
0
        static ValidationResult Setup(SplashScreen splashScreen)
        {
            var validator = new SPFInstalledValidator();

            if (validator.RunValidator() == ValidationResult.Error)
            {
                MessageBox.Show(validator.ErrorString+Environment.NewLine+Environment.NewLine+validator.QuestionString, SPMEnvironment.Version.Title + " Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return ValidationResult.Error;
            }

            var builder = new ContainerBuilder();

            // Find all the assemblies for this application
            builder.RegisterModule(new AutoLoadAssemblies());

            // Build the container now!
            autoFacContainer = builder.Build();
            //CompositionProvider.LoadAssemblies();

            IoCContainer = autoFacContainer.Resolve<IContainerAdapter>();

            var provider = IoCContainer.Resolve<SettingsProvider>();
            provider.Load();

            var engine = new PreflightController(splashScreen, IoCContainer);
            if (!engine.Validate())
            {
                return ValidationResult.Error;
            }

            Window = IoCContainer.Resolve<MainWindow>();
            Window.SplashScreenLoad(splashScreen);

            return ValidationResult.Success;
        }
Ejemplo n.º 54
0
 public override void MethodToBenchmark(IContainerAdapter container)
 {
     var combined1 = (ICombined1)container.Resolve(typeof(ICombined1));
     var combined2 = (ICombined2)container.Resolve(typeof(ICombined2));
     var combined3 = (ICombined3)container.Resolve(typeof(ICombined3));
 }
Ejemplo n.º 55
0
 private static void WarmUp(IContainerAdapter container)
 {
     var interface1 = container.Resolve<ISingleton>();
     var interface2 = container.Resolve<ITransient>();
     var combined = container.Resolve<ICombined>();
 }
Ejemplo n.º 56
0
        private static void WarmUp(IContainerAdapter container)
        {
            var interface1 = (ISingleton)container.Resolve(typeof(ISingleton));

            if (interface1 == null)
            {
                throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ISingleton)));
            }

            var interface2 = (ITransient)container.Resolve(typeof(ITransient));

            if (interface2 == null)
            {
                throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ITransient)));
            }

            var combined = (ICombined)container.Resolve(typeof(ICombined));

            if (combined == null)
            {
                throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ICombined)));
            }

            var complex = (IComplex)container.Resolve(typeof(IComplex));

            if (complex == null)
            {
                throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(IComplex)));
            }

            if (container.SupportGeneric)
            {
                var generic = (ImportGeneric<int>)container.Resolve(typeof(ImportGeneric<int>));

                if (generic == null)
                {
                    throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ImportGeneric<int>)));
                }
            }

            if (container.SupportsMultiple)
            {
                var importMultiple = (ImportMultiple)container.Resolve(typeof(ImportMultiple));

                if (importMultiple == null)
                {
                    throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ImportMultiple)));
                }
            }

            if (container.SupportsConditional)
            {
                var importObject = (ImportConditionObject)container.Resolve(typeof(ImportConditionObject));

                if (importObject == null)
                {
                    throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ImportConditionObject)));
                }

                var importObject2 = (ImportConditionObject2)container.Resolve(typeof(ImportConditionObject2));

                if (importObject2 == null)
                {
                    throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ImportConditionObject2)));
                }
            }

            if (container.SupportsInterception)
            {
                var calculator = (ICalculator)container.ResolveProxy(typeof(ICalculator));
                calculator.Add(1, 2);
            }
        }
Ejemplo n.º 57
0
        private static void MeasureResolvePerformance(IContainerAdapter container, Result outputResult)
        {
            var singletonWatch = new Stopwatch();
            var transientWatch = new Stopwatch();
            var combinedWatch = new Stopwatch();
            var conditionsWatch = new Stopwatch();
            var genericWatch = new Stopwatch();
            var complexWatch = new Stopwatch();
            var multipleWatch = new Stopwatch();

            for (int i = 0; i < LoopCount; i++)
            {
                singletonWatch.Start();
                var result1 = (ISingleton)container.Resolve(typeof(ISingleton));
                singletonWatch.Stop();

                transientWatch.Start();
                var result2 = (ITransient)container.Resolve(typeof(ITransient));
                transientWatch.Stop();

                combinedWatch.Start();
                var result3 = (ICombined)container.Resolve(typeof(ICombined));
                combinedWatch.Stop();

                complexWatch.Start();
                var complexResult = (IComplex)container.Resolve(typeof(IComplex));
                complexWatch.Stop();

                if (container.SupportsConditional)
                {
                    conditionsWatch.Start();
                    var result4 = (ImportConditionObject)container.Resolve(typeof(ImportConditionObject));
                    var result5 = (ImportConditionObject2)container.Resolve(typeof(ImportConditionObject2));
                    conditionsWatch.Stop();
                }

                if (container.SupportGeneric)
                {
                    genericWatch.Start();
                    var genericResult = (ImportGeneric<int>)container.Resolve(typeof(ImportGeneric<int>));
                    genericWatch.Stop();
                }

                if (container.SupportsMultiple)
                {
                    multipleWatch.Start();
                    var importMultiple = (ImportMultiple)container.Resolve(typeof(ImportMultiple));
                    multipleWatch.Stop();
                }
            }

            outputResult.SingletonTime = singletonWatch.ElapsedMilliseconds;
            outputResult.TransientTime = transientWatch.ElapsedMilliseconds;
            outputResult.CombinedTime = combinedWatch.ElapsedMilliseconds;
            outputResult.ComplexTime = complexWatch.ElapsedMilliseconds;

            if (container.SupportGeneric)
            {
                outputResult.GenericTime = genericWatch.ElapsedMilliseconds;
            }

            if (container.SupportsMultiple)
            {
                outputResult.MultipleImport = multipleWatch.ElapsedMilliseconds;
            }

            if (container.SupportsConditional)
            {
                outputResult.ConditionalTime = conditionsWatch.ElapsedMilliseconds;
            }
        }
Ejemplo n.º 58
0
        public void TransientLifetime(IContainerAdapter adapter)
        {
            adapter.RegisterTransient<IService, IndependentService>();
            var instance1 = adapter.Resolve<IService>();
            var instance2 = adapter.Resolve<IService>();

            Assert.NotSame(instance1, instance2);
        }
Ejemplo n.º 59
0
        private static void WarmUp(IContainerAdapter container)
        {
            var interface1 = (ISingleton)container.Resolve(typeof(ISingleton));

            if (interface1 == null)
            {
                throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ISingleton)));
            }

            var interface2 = (ITransient)container.Resolve(typeof(ITransient));

            if (interface2 == null)
            {
                throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ITransient)));
            }

            var combined = (ICombined)container.Resolve(typeof(ICombined));

            if (combined == null)
            {
                throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ICombined)));
            }

            var complex = (IComplex)container.Resolve(typeof(IComplex));

            if (complex == null)
            {
                throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(IComplex)));
            }

            if (container.SupportsPropertyInjection)
            {
                var propertyInjectionObject = (ComplexPropertyObject)container.Resolve(typeof(IComplexPropertyObject));
                var propertyInjectionObject2 = (ComplexPropertyObject)container.Resolve(typeof(IComplexPropertyObject));

                if (propertyInjectionObject == null || propertyInjectionObject2 == null)
                {
                    throw new Exception(
                         string.Format(
                         "Container {0} could not create type {1}",
                         container.PackageName,
                         typeof(IComplexPropertyObject)));
                }

                if (object.ReferenceEquals(propertyInjectionObject, propertyInjectionObject2) ||
                     !object.ReferenceEquals(propertyInjectionObject.ServiceA, propertyInjectionObject2.ServiceA) ||
                     !object.ReferenceEquals(propertyInjectionObject.ServiceB, propertyInjectionObject2.ServiceB) ||
                     !object.ReferenceEquals(propertyInjectionObject.ServiceC, propertyInjectionObject2.ServiceC) ||
                     object.ReferenceEquals(propertyInjectionObject.SubObjectA, propertyInjectionObject2.SubObjectA) ||
                     object.ReferenceEquals(propertyInjectionObject.SubObjectB, propertyInjectionObject2.SubObjectB) ||
                     object.ReferenceEquals(propertyInjectionObject.SubObjectC, propertyInjectionObject2.SubObjectC))
                {
                    throw new Exception(
                         string.Format(
                         "Container {0} could not correctly create type {1}",
                         container.PackageName,
                         typeof(IComplexPropertyObject)));
                }

                propertyInjectionObject.Verify(container.PackageName);
            }

            if (container.SupportGeneric)
            {
                var generic = (ImportGeneric<int>)container.Resolve(typeof(ImportGeneric<int>));

                if (generic == null)
                {
                    throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ImportGeneric<int>)));
                }
            }

            if (container.SupportsMultiple)
            {
                var importMultiple = (ImportMultiple)container.Resolve(typeof(ImportMultiple));

                if (importMultiple == null)
                {
                    throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ImportMultiple)));
                }
            }

            if (container.SupportsConditional)
            {
                var importObject = (ImportConditionObject)container.Resolve(typeof(ImportConditionObject));

                if (importObject == null)
                {
                    throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ImportConditionObject)));
                }

                var importObject2 = (ImportConditionObject2)container.Resolve(typeof(ImportConditionObject2));

                if (importObject2 == null)
                {
                    throw new Exception(string.Format("Container {0} could not create type {1}", container.PackageName, typeof(ImportConditionObject2)));
                }
            }

            if (container.SupportsInterception)
            {
                var calculator = (ICalculator)container.ResolveProxy(typeof(ICalculator));
                calculator.Add(1, 2);
            }

            if (container.SupportsChildContainer)
            {
                using (var childContainer = container.CreateChildContainerAdapter())
                {
                    childContainer.Prepare();

                    ICombined scopedCombined = (ICombined)childContainer.Resolve(typeof(ICombined));

                    if (scopedCombined == null)
                    {
                        throw new Exception(string.Format("Child Container {0} could not create type {1}", container.PackageName, typeof(ICombined)));
                    }

                    if (!(scopedCombined is ScopedCombined))
                    {
                        throw new Exception(string.Format("Child Container {0} resolved type incorrectly should have been {1} but was {2}", container.PackageName, typeof(ICombined), scopedCombined.GetType()));
                    }
                }
            }
        }