示例#1
0
        public static IEnumerable <IServiceLocationParameter> WithParameters([NotNull] this IHaveServiceLocator serviceLocator, [NotNull] params IServiceLocationParameter[] parameters)
        {
            CodeContracts.VerifyNotNull(serviceLocator, "serviceLocator");
            CodeContracts.VerifyNotNull(parameters, "parameters");

            return(parameters);
        }
        /// <summary>
        /// The get repository.
        /// </summary>
        /// <param name="serviceLocator">
        /// The service locator.
        /// </param>
        /// <typeparam name="T">
        /// </typeparam>
        /// <returns>
        /// The <see cref="IRepository{T}"/>.
        /// </returns>
        public static IRepository <T> GetRepository <T>([NotNull] this IHaveServiceLocator serviceLocator)
            where T : IEntity
        {
            CodeContracts.VerifyNotNull(serviceLocator, "serviceLocator");

            return(serviceLocator.Get <IRepository <T> >());
        }
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="haveLocator">
        /// The have locator.
        /// </param>
        /// <param name="named">
        /// The named.
        /// </param>
        /// <typeparam name="TService">
        /// </typeparam>
        /// <returns>
        /// The <see cref="TService"/>.
        /// </returns>
        public static TService Get <TService>([NotNull] this IHaveServiceLocator haveLocator, [NotNull] string named)
        {
            CodeContracts.VerifyNotNull(haveLocator, "haveLocator");
            CodeContracts.VerifyNotNull(named, "named");

            return(haveLocator.ServiceLocator.Get <TService>(named));
        }
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="haveLocator">
        /// The have locator.
        /// </param>
        /// <param name="named">
        /// The named.
        /// </param>
        /// <param name="instance">
        /// The instance.
        /// </param>
        /// <typeparam name="TService">
        /// </typeparam>
        /// <returns>
        /// The try get.
        /// </returns>
        public static bool TryGet <TService>(
            [NotNull] this IHaveServiceLocator haveLocator, [NotNull] string named, out TService instance)
        {
            CodeContracts.VerifyNotNull(haveLocator, "haveLocator");
            CodeContracts.VerifyNotNull(named, "named");

            return(haveLocator.ServiceLocator.TryGet(named, out instance));
        }
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="haveLocator">
        /// The have locator.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <typeparam name="TService">
        /// </typeparam>
        /// <returns>
        /// The <see cref="TService"/>.
        /// </returns>
        public static TService Get <TService>(
            [NotNull] this IHaveServiceLocator haveLocator, [NotNull] IEnumerable <IServiceLocationParameter> parameters)
        {
            CodeContracts.VerifyNotNull(haveLocator, "haveLocator");
            CodeContracts.VerifyNotNull(parameters, "parameters");

            return(haveLocator.ServiceLocator.Get <TService>(parameters));
        }
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="haveLocator">
        /// The have locator.
        /// </param>
        /// <param name="named">
        /// The named.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <typeparam name="TService">
        /// </typeparam>
        /// <returns>
        /// The <see cref="TService"/>.
        /// </returns>
        public static TService Get <TService>(
            [NotNull] this IHaveServiceLocator haveLocator, [NotNull] string named, [NotNull] IEnumerable <IServiceLocationParameter> parameters)
        {
            CodeContracts.ArgumentNotNull(haveLocator, "haveLocator");
            CodeContracts.ArgumentNotNull(named, "named");
            CodeContracts.ArgumentNotNull(parameters, "parameters");

            return(haveLocator.ServiceLocator.Get <TService>(named, parameters));
        }
        /// <summary>
        /// The run startup services.
        /// </summary>
        /// <param name="serviceLocator">
        /// The instance that has a service locator.
        /// </param>
        public static void RunStartupServices([NotNull] this IHaveServiceLocator serviceLocator)
        {
            CodeContracts.VerifyNotNull(serviceLocator, "serviceLocator");

            var startupServices = serviceLocator.Get <IEnumerable <IStartupService> >();

            // run critical first...
            startupServices.Where(s => s.HasInterface <ICriticalStartupService>()).OrderByDescending(i => i.Priority)
            .ForEach(service => service.Run());

            // run secondary...
            startupServices.Where(s => !s.HasInterface <ICriticalStartupService>()).OrderByDescending(i => i.Priority)
            .ForEach(service => service.Run());
        }
示例#8
0
        /// <summary>
        /// The send verification email.
        /// </summary>
        /// <param name="haveServiceLocator">
        /// The have service locator.
        /// </param>
        /// <param name="user"></param>
        public static void SendVerificationEmail(
            [NotNull] this IHaveServiceLocator haveServiceLocator, [NotNull] MembershipUser user, [NotNull] string email, int?userID, string newUsername = null)
        {
            CodeContracts.VerifyNotNull(email, "email");
            CodeContracts.VerifyNotNull(user, "user");
            CodeContracts.VerifyNotNull(haveServiceLocator, "haveServiceLocator");

            string hashinput = DateTime.UtcNow + email + Security.CreatePassword(20);
            string hash      = FormsAuthentication.HashPasswordForStoringInConfigFile(hashinput, "md5");

            // save verification record...
            haveServiceLocator.GetRepository <CheckEmail>().Save(userID, hash, user.Email);

            var verifyEmail = new YafTemplateEmail("VERIFYEMAIL");

            string subject = haveServiceLocator.Get <ILocalization>().GetTextFormatted("VERIFICATION_EMAIL_SUBJECT", haveServiceLocator.Get <YafBoardSettings>().Name);

            verifyEmail.TemplateParams["{link}"]      = YafBuildLink.GetLinkNotEscaped(ForumPages.approve, true, "k={0}", hash);
            verifyEmail.TemplateParams["{key}"]       = hash;
            verifyEmail.TemplateParams["{forumname}"] = haveServiceLocator.Get <YafBoardSettings>().Name;
            verifyEmail.TemplateParams["{forumlink}"] = "{0}".FormatWith(YafForumInfo.ForumURL);

            verifyEmail.SendEmail(new MailAddress(email, newUsername ?? user.UserName), subject, true);
        }
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="haveLocator">
        /// The have locator.
        /// </param>
        /// <typeparam name="TService">
        /// </typeparam>
        /// <returns>
        /// The <see cref="TService"/>.
        /// </returns>
        public static TService Get <TService>([NotNull] this IHaveServiceLocator haveLocator)
        {
            CodeContracts.VerifyNotNull(haveLocator, "haveLocator");

            return(haveLocator.ServiceLocator.Get <TService>());
        }
        /// <summary>
        /// The get.
        /// </summary>
        /// <param name="haveLocator">
        /// The have locator.
        /// </param>
        /// <param name="instance">
        /// The instance.
        /// </param>
        /// <typeparam name="TService">
        /// </typeparam>
        /// <returns>
        /// The try get.
        /// </returns>
        public static bool TryGet <TService>([NotNull] this IHaveServiceLocator haveLocator, out TService instance)
        {
            CodeContracts.ArgumentNotNull(haveLocator, "haveLocator");

            return(haveLocator.ServiceLocator.TryGet(out instance));
        }