Resolve() static private méthode

static private Resolve ( Type type ) : object
type Type
Résultat object
Exemple #1
0
        public void IEnumerableInConstructor()
        {
            Configuration configuration = new Configuration();

            configuration.Register(typeof(ICommon), typeof(First), Lifetime.Singleton, "First");
            configuration.Register(typeof(ICommon), typeof(Second), Lifetime.Singleton, "Second");
            configuration.Register(typeof(ICommonFrameEnumerable), typeof(CommonFrameEnumerable));
            DependencyInjector injector = new DependencyInjector(configuration);

            IEnumerable <ICommon> objects     = injector.Resolve <IEnumerable <ICommon> >();
            List <ICommon>        objectsList = new List <ICommon>();

            foreach (var obj in objects)
            {
                objectsList.Add(obj);
            }

            ICommonFrameEnumerable objectFrame    = injector.Resolve <ICommonFrameEnumerable>();
            IEnumerable <ICommon>  protoCheckList = objectFrame.All;
            List <ICommon>         checkList      = new List <ICommon>();

            foreach (var obj in protoCheckList)
            {
                checkList.Add(obj);
            }

            CollectionAssert.AreEquivalent(objectsList, checkList);
        }
Exemple #2
0
        public void AllCorrect()
        {
            Configuration configuration = new Configuration();

            configuration.Register <ICommon, First>(Lifetime.Singleton, "First");
            configuration.Register <ICommon, Second>(Lifetime.Singleton, "Second");
            DependencyInjector injector = new DependencyInjector(configuration);

            ICommon objFirst                  = injector.Resolve <ICommon>("First");
            ICommon objSecond                 = injector.Resolve <ICommon>("Second");
            IEnumerable <ICommon> objects     = injector.Resolve <IEnumerable <ICommon> >();
            List <ICommon>        objectsList = new List <ICommon>();

            foreach (var obj in objects)
            {
                objectsList.Add(obj);
            }

            List <ICommon> objectsCheck = new List <ICommon>()
            {
                objFirst, objSecond
            };

            CollectionAssert.AreEquivalent(objectsList, objectsCheck);
        }
Exemple #3
0
        public void InstanseDifferentAsself()
        {
            Configuration configuration = new Configuration();

            configuration.Register <First, First>(Lifetime.Instance);
            DependencyInjector injector = new DependencyInjector(configuration);

            First objFirst  = injector.Resolve <First>();
            First objSecond = injector.Resolve <First>();

            Assert.IsFalse(objFirst == objSecond);
        }
        public void DI_ShouldUse_NewInstance_WhenNotSingleton()
        {
            var diConfig = new DependencyInjectorConfiguration();

            diConfig.Register <IBase, ImplFor_IBase>(singleton: false);

            var di      = new DependencyInjector(diConfig);
            var actual1 = di.Resolve <IBase>();
            var actual2 = di.Resolve <IBase>();

            Assert.AreNotSame(actual1, actual2);
        }
Exemple #5
0
        public void SingletoneSameAsself()
        {
            Configuration configuration = new Configuration();

            configuration.Register <First, First>(Lifetime.Singleton);
            DependencyInjector injector = new DependencyInjector(configuration);

            First objFirst  = injector.Resolve <First>();
            First objSecond = injector.Resolve <First>();

            Assert.IsTrue(objFirst == objSecond);
        }
Exemple #6
0
        public void NamedCorrect()
        {
            Configuration configuration = new Configuration();

            configuration.Register <ICommon, First>("First");
            configuration.Register <ICommon, Second>("Second");
            DependencyInjector injector = new DependencyInjector(configuration);

            ICommon obj;

            obj = injector.Resolve <ICommon>("First");
            Assert.IsInstanceOfType(obj, typeof(First));

            obj = injector.Resolve <ICommon>("Second");
            Assert.IsInstanceOfType(obj, typeof(Second));
        }
Exemple #7
0
        public void NameAttributeInConstructor()
        {
            Configuration configuration = new Configuration();

            configuration.Register <ICommon, First>(Lifetime.Singleton, "First");
            configuration.Register <ICommon, Second>(Lifetime.Singleton, "Second");
            configuration.Register <ICommonFrameAttr, CommonFrameAttr>();
            DependencyInjector injector = new DependencyInjector(configuration);

            ICommon          objFirst  = injector.Resolve <ICommon>("First");
            ICommon          objSecond = injector.Resolve <ICommon>("Second");
            ICommonFrameAttr objFrame  = injector.Resolve <ICommonFrameAttr>();

            Assert.AreEqual(objFirst, objFrame.First);
            Assert.AreEqual(objSecond, objFrame.Second);
        }
Exemple #8
0
        public void ExceptionAll()
        {
            Configuration      configuration = new Configuration();
            DependencyInjector injector      = new DependencyInjector(configuration);

            Assert.ThrowsException <NotRegisteredException>(() => injector.Resolve <IEnumerable <ICommon> >());
        }
Exemple #9
0
        static void HandleRequest(string controllerName, string actionName, params object[] parameters)
        {
            var controllerType = FindControllers().FirstOrDefault(t => t.Name == controllerName);
            var controller     = _di.Resolve(controllerType);
            var result         = controllerType.InvokeMember(actionName, BindingFlags.InvokeMethod, null, controller, parameters);

            //other HTTP stuff happens here
        }
        public void DI_ShouldThrow_StackOverflowException_IfRecursionDetected()
        {
            var diConfig = new DependencyInjectorConfiguration();

            diConfig.Register <IBase, RecursionDepsImplFor_IBase>();

            var di     = new DependencyInjector(diConfig);
            var actual = di.Resolve <IBase>();
        }
        public AddRobotView()
        {
            InitializeComponent();
            var addRobotViewModel = DependencyInjector.Resolve <AddRobotViewModel>();

            addRobotViewModel.View = this;

            DataContext = addRobotViewModel;
        }
        public void DI_ShouldReturn_Null_IfNotRegistered()
        {
            var diConfig = new DependencyInjectorConfiguration();
            // register part skipped

            var di     = new DependencyInjector(diConfig);
            var actual = di.Resolve <IBase>();

            Assert.AreEqual(null, actual);
        }
Exemple #13
0
        public void ExceptionNamed()
        {
            Configuration configuration = new Configuration();

            configuration.Register <ICommon, First>("First");
            configuration.Register <ICommon, Second>("Second");
            DependencyInjector injector = new DependencyInjector(configuration);

            Assert.ThrowsException <NotRegisteredException>(() => injector.Resolve <ICommon>("Same"));
        }
Exemple #14
0
        public DataView()
        {
            InitializeComponent();

            var dataViewModel = DependencyInjector.Resolve <DataViewModel>();

            dataViewModel.View = this;

            DataContext = dataViewModel;
        }
Exemple #15
0
 private object[] GetParametersByInfos(ParameterInfo[] parameterInfos)
 {
     object[] parameters = new object[parameterInfos.Length];
     for (int i = 0; i < parameterInfos.Length; i++)
     {
         object?name = TryGetImplementationName(parameterInfos[i]);
         parameters[i] = dependencyInjector.Resolve(parameterInfos[i].ParameterType, name);
     }
     return(parameters);
 }
        public void DI_ShouldResolve_WhenOpenGenericDependency()
        {
            var diConfig = new DependencyInjectorConfiguration();

            diConfig.Register(typeof(IBaseWithDependency <>), typeof(ImplFor_IBaseWithDependency <>));

            var di     = new DependencyInjector(diConfig);
            var actual = di.Resolve <IBaseWithDependency <IEnumerable> >();

            Assert.AreEqual(typeof(ImplFor_IBaseWithDependency <ArrayList>), actual.GetType());
        }
Exemple #17
0
        public RntAppUserController(UserManager <RntAppUser> userManager,
                                    SignInManager <RntAppUser> signInManager,
                                    IOptions <SecureSettings> appSettings)
        {
            _userManager   = userManager;
            _signInManager = signInManager;
            _appSettings   = appSettings.Value;

            DependencyInjector.UpdateInterfaceModeDependencies(true);
            LogInService = DependencyInjector.Resolve <ILogInService>();
        }
        public void DI_ShouldResolve_WithInnerDependencies()
        {
            var diConfig = new DependencyInjectorConfiguration();

            diConfig.Register <IBase, InnerDepsImplFor_IBase>();

            var di     = new DependencyInjector(diConfig);
            var actual = di.Resolve <IBase>();

            Assert.AreEqual(typeof(InnerDepsImplFor_IBase), actual.GetType());
        }
Exemple #19
0
        public LecturerSampleDataController(IOptions <AppGlobalSettings> appGlobalSettings)
        {
            AppGlobalSettings = appGlobalSettings.Value;
            DataConnectionSettingsPathFile = AppGlobalSettings.DataConnectionSettingsPathFile;

            var dataConnectionSettings = JsonConvert.DeserializeObject <DataConnectionSettings>(System.IO.File.ReadAllText(DataConnectionSettingsPathFile));

            DependencyInjector.UpdateInterfaceModeDependencies(dataConnectionSettings);

            LecturerService = DependencyInjector.Resolve <ILecturerService>();
        }
        public async Task <ActionResult <ApiReturnValue <Subjects> > > PostSubject(Subject subject)
        {
            var dataConnectionSettings = JsonConvert.DeserializeObject <DataConnectionSettings>(System.IO.File.ReadAllText(DataConnectionSettingsPathFile));

            DependencyInjector.UpdateInterfaceModeDependencies(dataConnectionSettings);
            var subjectService = DependencyInjector.Resolve <ISubjectService>();


            var apiReturnValue = await subjectService.CreateSubject(subject);

            return(apiReturnValue);
        }
Exemple #21
0
        public void OpenGenericParam()
        {
            Configuration configuration = new Configuration();

            configuration.Register(typeof(IFirstPattern), typeof(FirstPattern));
            configuration.Register(typeof(ISmallPattern <IFirstPattern>), typeof(SmallPattern <IFirstPattern>));
            DependencyInjector injector = new DependencyInjector(configuration);

            ISmallPattern <IFirstPattern> main = injector.Resolve <ISmallPattern <IFirstPattern> >();

            //Assert.IsInstanceOfType(main.First, typeof(FirstPattern));
            Assert.IsInstanceOfType(main, typeof(SmallPattern <IFirstPattern>));
        }
        public void DI_ShouldReturn_MultipleImplementations_ForOneDependency()
        {
            var diConfig = new DependencyInjectorConfiguration();

            diConfig.Register <IBase, ImplFor_IBase>();
            diConfig.Register <IBase, ImplFor_IBase_2>();

            var di     = new DependencyInjector(diConfig);
            var actual = di.Resolve <IEnumerable <IBase> >();

            Assert.AreEqual(typeof(ImplFor_IBase), actual.First().GetType());
            Assert.AreEqual(typeof(ImplFor_IBase_2), actual.Last().GetType());
        }
        public async Task <IActionResult> PutSubject(string id, Subject subject)
        {
            if (id != subject.SubjectCode)
            {
                return(BadRequest());
            }

            var dataConnectionSettings = JsonConvert.DeserializeObject <DataConnectionSettings>(System.IO.File.ReadAllText(DataConnectionSettingsPathFile));

            DependencyInjector.UpdateInterfaceModeDependencies(dataConnectionSettings);
            var subjectService = DependencyInjector.Resolve <ISubjectService>();
            var retSubject     = await subjectService.UpdateSubject(id, subject);

            return(NoContent());
        }
        public MainWindowView()
        {
            InitializeComponent();

            var mainWindowViewModel = DependencyInjector.Resolve <MainWindowViewModel>();

            mainWindowViewModel.View = this;
            Closing += mainWindowViewModel.OnWindowClosing;

            DataContext = mainWindowViewModel;

            Uri iconUri = new Uri("pack://application:,,,/Images/monitor.jpg", UriKind.RelativeOrAbsolute);

            Icon = BitmapFrame.Create(iconUri);
        }
Exemple #25
0
        public void OpenGenericTwo()
        {
            Configuration configuration = new Configuration();

            configuration.Register(typeof(IFirstPattern), typeof(FirstPattern));
            configuration.Register(typeof(ISecondPattern), typeof(SecondPattern));
            configuration.Register(typeof(IBigPattern <,>), typeof(BigPattern <,>));
            DependencyInjector injector = new DependencyInjector(configuration);

            IBigPattern <IFirstPattern, ISecondPattern> main = injector.Resolve <IBigPattern <IFirstPattern, ISecondPattern> >();

            Assert.IsInstanceOfType(main.First, typeof(FirstPattern));
            Assert.IsInstanceOfType(main.Second, typeof(SecondPattern));
            Assert.IsInstanceOfType(main, typeof(BigPattern <IFirstPattern, ISecondPattern>));
        }
Exemple #26
0
        public void Nested()
        {
            Configuration configuration = new Configuration();

            configuration.Register(typeof(INestedOne), typeof(NestedOne));
            configuration.Register(typeof(INestedTwo), typeof(NestedTwo));
            configuration.Register(typeof(INestedThree), typeof(NestedThree));
            DependencyInjector injector = new DependencyInjector(configuration);

            INestedOne main = injector.Resolve <INestedOne>();

            Assert.IsInstanceOfType(main, typeof(NestedOne));
            Assert.IsInstanceOfType(main.Nested, typeof(NestedTwo));
            Assert.IsInstanceOfType(main.Nested.Nested, typeof(NestedThree));
        }
        public async Task <ActionResult <ApiReturnValue <Subjects> > > GetSubjects(int pageSize = 100, int pageNumber = 1)
        {
            var dataConnectionSettings = JsonConvert.DeserializeObject <DataConnectionSettings>(System.IO.File.ReadAllText(DataConnectionSettingsPathFile));

            DependencyInjector.UpdateInterfaceModeDependencies(dataConnectionSettings);
            var subjectService = DependencyInjector.Resolve <ISubjectService>();

            var apiReturnValue = await subjectService.GetSubject(pageSize, pageNumber);

            if (apiReturnValue == null)
            {
                return(NotFound());
            }

            return(apiReturnValue);
        }
        public void GetByIdTest()
        {
            var testRepository = DependencyInjector.Resolve <IAsyncRepository <FactoryEntity> >();

            Assert.IsNotNull(testRepository);
            var factory = testRepository.GetById(1);

            factory.Wait();
            Assert.IsNotNull(factory);
            Assert.IsInstanceOf <FactoryEntity>(factory.Result);

            var factoryEntity = factory.Result;

            // Test resulting object
            Assert.AreEqual(1, factoryEntity.Id);
            Assert.AreEqual("Warehouse factory", factoryEntity.Name);
        }
        internal async void OnLoaded(object sender, EventArgs e)
        {
            var factory = await FactoryService.GetFactoryById(1);

            var factoryRobots = factory.Robots;

            var descartesRobotFactory = DependencyInjector.Resolve <DescartesRobotFactory>();

            foreach (var robot in factoryRobots)
            {
                var warehouseRobot = new WarehouseRobot(Guid.Parse(robot.Guid), descartesRobotFactory);
                warehouseRobot.Title = robot.Name;
                descartesRobotFactory.Robots.Add(warehouseRobot);
            }

            RobotFactories.Add(descartesRobotFactory);
        }
Exemple #30
0
        public DashboardView()
        {
            InitializeComponent();

            var dashboardViewControlModel = DependencyInjector.Resolve <DashboardViewModel>();

            dashboardViewControlModel.View = this;

            Closing += dashboardViewControlModel.OnClosing;
            Loaded  += dashboardViewControlModel.OnLoaded;

            DataContext = dashboardViewControlModel;

            Uri iconUri = new Uri("pack://application:,,,/Images/robot.png", UriKind.RelativeOrAbsolute);

            Icon = BitmapFrame.Create(iconUri);
        }