コード例 #1
0
        public static void AddInstance(object _class)
        {
            if (Instance?.Container == null)
            {
                var ex = new InitializeExceptions();
                Methods.Report($"MVVMInit.RegisterServiceForClass>", ex);
                throw ex;
            }
            //Instance.builder.RegisterIn
            var builder = new ContainerBuilder();

            builder.RegisterInstance(_class).AsImplementedInterfaces();
            builder.Update(Instance.Container);
        }
コード例 #2
0
        public static T GetService <T>()
        {
            if (Instance?.Container == null)
            {
                var ex = new InitializeExceptions();
                Methods.Report($"MVVMInit.GetService<{typeof(T)?.FullName}>", ex);
                throw ex;
            }
            object result = null;

            if (Instance?.Container.TryResolve(typeof(T), out result) == true)
            {
                return((T)result);
            }
            else
            {
                return(default(T));
            }
        }