Пример #1
0
        /// <summary>
        /// Try to get a registration with either Interface, ViewModel or Model type matching <c>T</c>
        /// </summary>
        /// <typeparam name="T">Interface, ViewModel or Model type of the registration</typeparam>
        /// <param name="registrationInfo"></param>
        /// <returns><c>true</c> if there was a matching registration, otherwise <c>false</c></returns>
        public static bool TryGetRegistration <T>(
            out RegistrationInfo registrationInfo)
        {
            registrationInfo = _registrations?.FirstOrDefault(registration =>
                                                              registration.Interface == typeof(T) ||
                                                              registration.ViewModel == typeof(T) ||
                                                              registration.Model == typeof(T));


            return(registrationInfo != null);
        }
Пример #2
0
        public static RegistrationInfo Register <TImplementation>()

            where TImplementation : class, IViewModel
        {
            var registrationInfo = new RegistrationInfo(
                typeof(TImplementation));

            RegisterInternal(
                registrationInfo);


            return(registrationInfo);
        }
Пример #3
0
        public static RegistrationInfo DontInitialize(
            this RegistrationInfo registration)
        {
            if (!_registrations.Contains(
                    registration))
            {
                RegisterInternal(
                    registration);
            }


            registration.Initialize = false;


            return(registration);
        }
Пример #4
0
        private static void RegisterInternal(
            RegistrationInfo registration)
        {
            _registrations.Add(registration);


            // dont know what happens in different dependency container implementations when both types are the same
            if (registration.Interface == registration.ViewModel)
            {
                container.RegisterType(
                    registration.Interface);
            }
            else
            {
                container.RegisterType(
                    registration.Interface,
                    registration.ViewModel);
            }
        }