Beispiel #1
0
        /// <summary>
        /// 获取绝对路径
        /// </summary>
        /// <param name="virtualPath">虚拟路径</param>
        /// <returns></returns>
        public static string GetAbsolutePath(string virtualPath)
        {
            string path = virtualPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);

            if (path[0] == '~')
            {
                path = path.Remove(0, 2);
            }
            string rootPath = AutofacHelper.GetScopeService <IHostingEnvironment>().WebRootPath;

            return(Path.Combine(rootPath, path));
        }
Beispiel #2
0
 /// <summary>
 /// 获取URL
 /// </summary>
 /// <param name="virtualUrl">虚拟URL</param>
 /// <returns></returns>
 public static string GetUrl(string virtualUrl)
 {
     if (virtualUrl.IsNullOrEmpty())
     {
         throw new ArgumentNullException("虚拟Url不能为NULL或者空!");
     }
     else
     {
         UrlHelper urlHelper = new UrlHelper(AutofacHelper.GetScopeService <IActionContextAccessor>().ActionContext);
         return(urlHelper.Content(virtualUrl));
     }
 }
Beispiel #3
0
        /// <summary>
        /// 获取数据库连接对象DbConnection
        /// </summary>
        /// <param name="dbType">数据库类型</param>
        /// <returns></returns>
        public static DbConnection GetDbConnection(DatabaseType dbType)
        {
            var con = GetDbProviderFactory(dbType).CreateConnection();

            //请求结束自动释放
            try
            {
                AutofacHelper.GetScopeService <IDisposableContainer>().AddDisposableObj(con);
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }
            return(con);
        }
Beispiel #4
0
        static ConfigHelper()
        {
            IConfiguration config = null;

            try
            {
                config = AutofacHelper.GetScopeService <IConfiguration>();
            }
            catch (Exception ex)
            {
                throw ex.InnerException;
            }

            if (config == null)
            {
                var builder = new ConfigurationBuilder()
                              .SetBasePath(AppContext.BaseDirectory)
                              .AddJsonFile("appsettings.json");
                config = builder.Build();
            }
            _config = config;
        }