Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="function"></param>
        public static void Register <T>(Func <object> function)
        {
            Type          typeFromHandle = typeof(T);
            Lazy <object> lazy           = new Lazy <object>(function);

            RepositoryContainer.Repositorys.AddOrUpdate(RepositoryContainer.GetKey(typeFromHandle), lazy, (string x, Lazy <object> y) => lazy);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public static void Register <T>() where T : new()
        {
            Type          typeFromHandle = typeof(T);
            Lazy <object> lazy           = new Lazy <object>(() => (default(T) == null) ? Activator.CreateInstance <T>() : default(T));

            RepositoryContainer.Repositorys.AddOrUpdate(RepositoryContainer.GetKey(typeFromHandle), lazy, (string x, Lazy <object> y) => lazy);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Resolve <T>() where T : new()
        {
            Type          typeFromHandle = typeof(T);
            string        key            = RepositoryContainer.GetKey(typeFromHandle);
            Lazy <object> orAdd          = RepositoryContainer.Repositorys.GetOrAdd(key, (string x) => new Lazy <object>(() => (default(T) == null) ? Activator.CreateInstance <T>() : default(T)));

            return((T)((object)orAdd.Value));
        }