主頁 > .NET開發 > (三)學習了解OrchardCore筆記——靈魂中間件ModularTenantContainerMiddleware的第一行①的模塊部分

(三)學習了解OrchardCore筆記——靈魂中間件ModularTenantContainerMiddleware的第一行①的模塊部分

2020-09-10 21:31:33 .NET開發

  了解到了OrchardCore主要由兩個中間件(ModularTenantContainerMiddleware和ModularTenantRouterMiddleware)構成,下面開始了解ModularTenantContainerMiddleware中間件第一行代碼,

  了解asp.net core機制的都知道中間件是由建構式和Invoke(或者InokeAsync)方法構成,建構式不過就是個依賴注入的程序,Invoke也可以直接依賴注入,兩者的區別是建構式時全域的,Invoke只是當次請求,所以從Inovke開始了解!

public async Task Invoke(HttpContext httpContext)
        {
            // Ensure all ShellContext are loaded and available.
            await _shellHost.InitializeAsync();

            var shellSettings = _runningShellTable.Match(httpContext);

            // We only serve the next request if the tenant has been resolved.
            if (shellSettings != null)
            {
                if (shellSettings.State == TenantState.Initializing)
                {
                    httpContext.Response.Headers.Add(HeaderNames.RetryAfter, "10");
                    httpContext.Response.StatusCode = StatusCodes.Status503ServiceUnavailable;
                    await httpContext.Response.WriteAsync("The requested tenant is currently initializing.");
                    return;
                }

                // Makes 'RequestServices' aware of the current 'ShellScope'.
                httpContext.UseShellScopeServices();

                var shellScope = await _shellHost.GetScopeAsync(shellSettings);

                // Holds the 'ShellContext' for the full request.
                httpContext.Features.Set(new ShellContextFeature
                {
                    ShellContext = shellScope.ShellContext,
                    OriginalPath = httpContext.Request.Path,
                    OriginalPathBase = httpContext.Request.PathBase
                });

                await shellScope.UsingAsync(scope => _next.Invoke(httpContext));
            }
        }

  現在從第一行代碼_shellHost.InitializeAsync()開始看起,_shellHost是一個IShellHost單例,是類ShellHost的實體化,這個很明顯就是asp.net core自帶的依賴注入生成的(這是在注冊服務的時候已經配置好的,具體追蹤services.AddOrchardCms就很清晰了),現在直接找ShellHost的InitializeAsync方法和PreCreateAndRegisterShellsAsync方法,

        public async Task InitializeAsync()
        {
            if (!_initialized)
            {
                // Prevent concurrent requests from creating all shells multiple times
                await _initializingSemaphore.WaitAsync();
                try
                {
                    if (!_initialized)
                    {
                        await PreCreateAndRegisterShellsAsync();
                    }
                }
                finally
                {
                    _initialized = true;
                    _initializingSemaphore.Release();
                }
            }
        }

     private async Task PreCreateAndRegisterShellsAsync()
        {
            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Start creation of shells");
            }

            // Load all extensions and features so that the controllers are registered in
            // 'ITypeFeatureProvider' and their areas defined in the application conventions.
            var features = _extensionManager.LoadFeaturesAsync();

            // Is there any tenant right now?
            var allSettings = (await _shellSettingsManager.LoadSettingsAsync()).Where(CanCreateShell).ToArray();
            var defaultSettings = allSettings.FirstOrDefault(s => s.Name == ShellHelper.DefaultShellName);
            var otherSettings = allSettings.Except(new[] { defaultSettings }).ToArray();

            await features;

            // The 'Default' tenant is not running, run the Setup.
            if (defaultSettings?.State != TenantState.Running)
            {
                var setupContext = await CreateSetupContextAsync(defaultSettings);
                AddAndRegisterShell(setupContext);
                allSettings = otherSettings;
            }

            if (allSettings.Length > 0)
            {
                // Pre-create and register all tenant shells.
                foreach (var settings in allSettings)
                {
                    AddAndRegisterShell(new ShellContext.PlaceHolder { Settings = settings });
                };
            }

            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Done pre-creating and registering shells");
            }
        }

  InitializeAsync從字面上看就是初始的程序ShellHost(這個不知道怎么翻譯比較準確)的程序,從代碼上看也是如此,

  首先通過_initialized判斷是否初始化過(開始沒賦值肯定false),在初始化結束_initialized就會設定為true,往下幾行的finally里面可以看到_initialized = true,因為ShellHost是單例,也就是啟動程式之后就會一直維持_initialized = true,簡單說就是啟動時會初始化一次ShellHost,

  再往下看,await _initializingSemaphore.WaitAsync,這個上面也有注釋防止并發請求多次創建所有shells,這個開始我也不懂的時候直接理解為lock后面finally的_initializingSemaphore.Release就是lock結束,后面找了點資料試了下,其實就是只有一個請求可以進入初始化,建構式只允許一個請求(SemaphoreSlim _initializingSemaphore = new SemaphoreSlim(1)),之所以說請求時因為這是中間件里面啊,每個請求都要通過中間件(這個得了解asp.net core中間件的原理),看了OrchardCore真給我帶來不少知識點,沒遇到這個我只知道多執行緒用lock鎖住,原來還可以有這樣的細節,

  然后try里又確認一次有沒初始化(判斷_initialized),為啥呢?我一臉懵逼,后面感覺好像可以接受,比較前面時有很多請求,說不定有個某個請求已經初始化ShellHost了呢,所以_initializingSemaphore.WaitAsync開始后又要確認一次,如果前面不先確認,那么又全部只能一個請求進來,這就很不合理了,我快被繞暈了,真佩服開發者的大腦,

  終于來到PreCreateAndRegisterShellsAsync方法了,_loggoer部分直接跳過,就是asp.net core的日志記錄而已,OrchardCore是一個模塊化多租戶的cms,模塊化就體現在這里,

var features = _extensionManager.LoadFeaturesAsync();

  加載所有的功能,ExtensionManager(OrchardCore\OrchardCore\Extensions\ExtensionManager.cs)的LoadFeaturesAsync方法,

        public async Task<IEnumerable<FeatureEntry>> LoadFeaturesAsync()
        {
            await EnsureInitializedAsync();
            return _features.Values;
        }

  確保初始化并回傳FeatureEntry集合,也就是所有功能的集合,現在進入EnsureInitializedAsync方法看看:

        private async Task EnsureInitializedAsync()
        {
            if (_isInitialized)
            {
                return;
            }

            await _semaphore.WaitAsync();

            try
            {
                if (_isInitialized)
                {
                    return;
                }

                var modules = _applicationContext.Application.Modules;
                var loadedExtensions = new ConcurrentDictionary<string, ExtensionEntry>();

                // Load all extensions in parallel
                await modules.ForEachAsync((module) =>
                {
                    if (!module.ModuleInfo.Exists)
                    {
                        return Task.CompletedTask;
                    }
                    var manifestInfo = new ManifestInfo(module.ModuleInfo);

                    var extensionInfo = new ExtensionInfo(module.SubPath, manifestInfo, (mi, ei) =>
                    {
                        return _featuresProvider.GetFeatures(ei, mi);
                    });

                    var entry = new ExtensionEntry
                    {
                        ExtensionInfo = extensionInfo,
                        Assembly = module.Assembly,
                        ExportedTypes = module.Assembly.ExportedTypes
                    };

                    loadedExtensions.TryAdd(module.Name, entry);

                    return Task.CompletedTask;
                });

                var loadedFeatures = new Dictionary<string, FeatureEntry>();

                // Get all valid types from any extension
                var allTypesByExtension = loadedExtensions.SelectMany(extension =>
                    extension.Value.ExportedTypes.Where(IsComponentType)
                    .Select(type => new
                    {
                        ExtensionEntry = extension.Value,
                        Type = type
                    })).ToArray();

                var typesByFeature = allTypesByExtension
                    .GroupBy(typeByExtension => GetSourceFeatureNameForType(
                        typeByExtension.Type,
                        typeByExtension.ExtensionEntry.ExtensionInfo.Id))
                    .ToDictionary(
                        group => group.Key,
                        group => group.Select(typesByExtension => typesByExtension.Type).ToArray());

                foreach (var loadedExtension in loadedExtensions)
                {
                    var extension = loadedExtension.Value;

                    foreach (var feature in extension.ExtensionInfo.Features)
                    {
                        // Features can have no types
                        if (typesByFeature.TryGetValue(feature.Id, out var featureTypes))
                        {
                            foreach (var type in featureTypes)
                            {
                                _typeFeatureProvider.TryAdd(type, feature);
                            }
                        }
                        else
                        {
                            featureTypes = Array.Empty<Type>();
                        }

                        loadedFeatures.Add(feature.Id, new CompiledFeatureEntry(feature, featureTypes));
                    }
                };

                // Feature infos and entries are ordered by priority and dependencies.
                _featureInfos = Order(loadedFeatures.Values.Select(f => f.FeatureInfo));
                _features = _featureInfos.ToDictionary(f => f.Id, f => loadedFeatures[f.Id]);

                // Extensions are also ordered according to the weight of their first features.
                _extensionsInfos = _featureInfos.Where(f => f.Id == f.Extension.Features.First().Id)
                    .Select(f => f.Extension);

                _extensions = _extensionsInfos.ToDictionary(e => e.Id, e => loadedExtensions[e.Id]);

                _isInitialized = true;
            }
            finally
            {
                _semaphore.Release();
            }
        }

  前面判斷初始化,多請求方面跟之前的是一樣的,這里我又不理解了,之前不是判斷過了嗎,難道是因為這是個Task的原因導致可能跳出到其它執行緒!這里先跳過!

  var modules = _applicationContext.Application.Modules;這里是通過反射得到所有的模塊,至于程序真是一言難盡啊,這里卡了我好幾個星期才明白究竟是個怎樣的程序,

  看下OrchardCore\OrchardCore.Abstractions\Modules\ModularApplicationContext.cs這個類

    public interface IApplicationContext
    {
        Application Application { get; }
    }

    public class ModularApplicationContext : IApplicationContext
    {
        private readonly IHostEnvironment _environment;
        private readonly IEnumerable<IModuleNamesProvider> _moduleNamesProviders;
        private Application _application;
        private static readonly object _initLock = new object();

        public ModularApplicationContext(IHostEnvironment environment, IEnumerable<IModuleNamesProvider> moduleNamesProviders)
        {
            _environment = environment;
            _moduleNamesProviders = moduleNamesProviders;
        }

        public Application Application
        {
            get
            {
                EnsureInitialized();
                return _application;
            }
        }

        private void EnsureInitialized()
        {
            if (_application == null)
            {
                lock (_initLock)
                {
                    if (_application == null)
                    {
                        _application = new Application(_environment, GetModules());
                    }
                }
            }
        }

        private IEnumerable<Module> GetModules()
        {
            var modules = new ConcurrentBag<Module>();
            modules.Add(new Module(_environment.ApplicationName, true));

            var names = _moduleNamesProviders
                .SelectMany(p => p.GetModuleNames())
                .Where(n => n != _environment.ApplicationName)
                .Distinct();

            Parallel.ForEach(names, new ParallelOptions { MaxDegreeOfParallelism = 8 }, (name) =>
            {
                modules.Add(new Module(name, false));
            });

            return modules;
        }
    }

  明顯就是初始化Application,然后回傳Application,首先看EnsureInitialized方法,然后就直接看GetModules方法,

  第一行var modules = new ConcurrentBag<Module>();又觸碰到我的知識盲點了,作為一個只會用List<T>的人,我真的完全不知道ConcurrentBag<T>是什么,馬上msdn下,原來ConcurrentBag<T>也是個集合,但是它是執行緒安全的,ok,集合開始添加資料,首先把當前專案的名稱OrchardCore.Cms.Web給加進去(modules.Add(new Module(_environment.ApplicationName, true));),然后看

var names = _moduleNamesProviders
                .SelectMany(p => p.GetModuleNames())
                .Where(n => n != _environment.ApplicationName)
                .Distinct();

  找到_moduleNamesProviders的實體(雖然是個集合,但是只有一個類實作了)AssemblyAttributeModuleNamesProvider,打開這個類,直接看建構式,

public class AssemblyAttributeModuleNamesProvider : IModuleNamesProvider
    {
        private readonly List<string> _moduleNames;

        public AssemblyAttributeModuleNamesProvider(IHostEnvironment hostingEnvironment)
        {
            var assembly = Assembly.Load(new AssemblyName(hostingEnvironment.ApplicationName));
            _moduleNames = assembly.GetCustomAttributes<ModuleNameAttribute>().Select(m => m.Name).ToList();
        }

        public IEnumerable<string> GetModuleNames()
        {
            return _moduleNames;
        }
    }

  明顯的反射,通過讀取當前程式的程式集hostingEnvironment.ApplicationName就是OrchardCore.Cms.Web,也就是獲取OrchardCore.Cms.Web.dll所有自定義ModuleName屬性的Name集合(看下ModuleNameAttribute可以明白就是建構式傳入的那個字串),編譯一下程式,用反編譯工具讀取OrchardCore.Cms.Web.dll(ModuleName哪里來的下篇再說,這也是我一直不明白卡了好幾個星期的地方)可以看到如下的ModuleName

  回傳ModularApplicationContext繼續看,就是用linq呼叫GetModuleNames方法把List<string>抽象成集合IEnumerable<string>通過篩選唯一值Distinct回傳(當然排除掉當前專案,畢竟前面已經加入過執行緒安全集合了modules)names,然后通過多執行緒方法加入前面提到那個執行緒安全集合modules,然后把執行緒安全集合回傳,

       var names = _moduleNamesProviders
                .SelectMany(p => p.GetModuleNames())
                .Where(n => n != _environment.ApplicationName)
                .Distinct();

            Parallel.ForEach(names, new ParallelOptions { MaxDegreeOfParallelism = 8 }, (name) =>
            {
                modules.Add(new Module(name, false));
            });

  學c#第一個多執行緒類就是Parallel,因此很清楚就是限制最大8個執行緒(為啥要限制最大8個執行緒,難道作者是用老i7那種4核8執行緒那種?),把names分別再多個執行緒傳遞給Module實體化然后加入執行緒安全集合modules回傳出去給Application做建構式的是引數實體化,這也是為啥要用執行緒安全集合的原因吧(我真哭了,像我這種菜鳥估計只會List<T>,然后foreach這種低效率的單執行緒方法了),

  ok,貼下Application類

  public class Application
    {
        private readonly Dictionary<string, Module> _modulesByName;
        private readonly List<Module> _modules;

        public const string ModulesPath = "Areas";
        public const string ModulesRoot = ModulesPath + "/";

        public const string ModuleName = "Application Main Feature";
        public const string ModuleDescription = "Provides components defined at the application level.";
        public static readonly string ModulePriority = int.MinValue.ToString();
        public const string ModuleCategory = "Application";

        public const string DefaultFeatureId = "Application.Default";
        public const string DefaultFeatureName = "Application Default Feature";
        public const string DefaultFeatureDescription = "Adds a default feature to the application's module.";

        public Application(IHostEnvironment environment, IEnumerable<Module> modules)
        {
            Name = environment.ApplicationName;
            Path = environment.ContentRootPath;
            Root = Path + '/';
            ModulePath = ModulesRoot + Name;
            ModuleRoot = ModulePath + '/';

            Assembly = Assembly.Load(new AssemblyName(Name));

            _modules = new List<Module>(modules);
            _modulesByName = _modules.ToDictionary(m => m.Name, m => m);
        }

        public string Name { get; }
        public string Path { get; }
        public string Root { get; }
        public string ModulePath { get; }
        public string ModuleRoot { get; }
        public Assembly Assembly { get; }
        public IEnumerable<Module> Modules => _modules;

        public Module GetModule(string name)
        {
            if (!_modulesByName.TryGetValue(name, out var module))
            {
                return new Module(string.Empty);
            }

            return module;
        }
    }

  前面獲取所有模塊也就是Modules屬性可以清晰的從建構式那里看到就是我們剛付訓傳的執行緒安全集合modules,繞來繞去我都快被繞暈了,真想一個指標指過去,好了,繼續回到我們的初始化功能,就是ExtensionManager的EnsureInitializedAsync方法

        private async Task EnsureInitializedAsync()
        {
            if (_isInitialized)
            {
                return;
            }

            await _semaphore.WaitAsync();

            try
            {
                if (_isInitialized)
                {
                    return;
                }

                var modules = _applicationContext.Application.Modules;
                var loadedExtensions = new ConcurrentDictionary<string, ExtensionEntry>();

                // Load all extensions in parallel
                await modules.ForEachAsync((module) =>
                {
                    if (!module.ModuleInfo.Exists)
                    {
                        return Task.CompletedTask;
                    }
                    var manifestInfo = new ManifestInfo(module.ModuleInfo);

                    var extensionInfo = new ExtensionInfo(module.SubPath, manifestInfo, (mi, ei) =>
                    {
                        return _featuresProvider.GetFeatures(ei, mi);
                    });

                    var entry = new ExtensionEntry
                    {
                        ExtensionInfo = extensionInfo,
                        Assembly = module.Assembly,
                        ExportedTypes = module.Assembly.ExportedTypes
                    };

                    loadedExtensions.TryAdd(module.Name, entry);

                    return Task.CompletedTask;
                });

                var loadedFeatures = new Dictionary<string, FeatureEntry>();

                // Get all valid types from any extension
                var allTypesByExtension = loadedExtensions.SelectMany(extension =>
                    extension.Value.ExportedTypes.Where(IsComponentType)
                    .Select(type => new
                    {
                        ExtensionEntry = extension.Value,
                        Type = type
                    })).ToArray();

                var typesByFeature = allTypesByExtension
                    .GroupBy(typeByExtension => GetSourceFeatureNameForType(
                        typeByExtension.Type,
                        typeByExtension.ExtensionEntry.ExtensionInfo.Id))
                    .ToDictionary(
                        group => group.Key,
                        group => group.Select(typesByExtension => typesByExtension.Type).ToArray());

                foreach (var loadedExtension in loadedExtensions)
                {
                    var extension = loadedExtension.Value;

                    foreach (var feature in extension.ExtensionInfo.Features)
                    {
                        // Features can have no types
                        if (typesByFeature.TryGetValue(feature.Id, out var featureTypes))
                        {
                            foreach (var type in featureTypes)
                            {
                                _typeFeatureProvider.TryAdd(type, feature);
                            }
                        }
                        else
                        {
                            featureTypes = Array.Empty<Type>();
                        }

                        loadedFeatures.Add(feature.Id, new CompiledFeatureEntry(feature, featureTypes));
                    }
                };

                // Feature infos and entries are ordered by priority and dependencies.
                _featureInfos = Order(loadedFeatures.Values.Select(f => f.FeatureInfo));
                _features = _featureInfos.ToDictionary(f => f.Id, f => loadedFeatures[f.Id]);

                // Extensions are also ordered according to the weight of their first features.
                _extensionsInfos = _featureInfos.Where(f => f.Id == f.Extension.Features.First().Id)
                    .Select(f => f.Extension);

                _extensions = _extensionsInfos.ToDictionary(e => e.Id, e => loadedExtensions[e.Id]);

                _isInitialized = true;
            }
            finally
            {
                _semaphore.Release();
            }
        }

  現在modules有了,下行是var loadedExtensions = new ConcurrentDictionary<string, ExtensionEntry>();經過剛剛的執行緒安全集合,ConcurrentDictionary雖然接觸不多也明白這個是執行緒安全字典(學依賴注入的時候遇到過),既然是執行緒安全字典,下面肯定又是多執行緒來填充這個執行緒安全字典loadedExtensions,這里用了一個ForEachAsync的擴展方法分配多個任務,把每個modules的ManifestInfo分析出來的功能加入ConcurrentDictionary,具體細說估計篇幅太長了,先簡單介紹下吧,之前modules就是OrchardCore.Modules、OrchardCore.Modules.Cms和OrchardCore.Themes這三個解決方案下的專案集合,我們稱作模塊集合,每個模塊由一個或者多個功能組成,現在就是把功能封裝成執行緒安全的字典集合,而功能是有重復的,可能多個模塊用同一個功能,所以執行緒安全很重要!下篇要解釋下反射那些ModuleName是如何實作的(畢竟困擾我這么久的東西必須記錄下才能印象深刻),我看下下篇能不能把功能拆出來說吧,

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/3527.html

標籤:.NET Core

上一篇:閑談設計模式

下一篇:通過Windows Visual Studio遠程除錯WSL2中的.NET Core Linux應用程式

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • WebAPI簡介

    Web體系結構: 有三個核心:資源(resource),URL(統一資源識別符號)和表示 他們的關系是這樣的:一個資源由一個URL進行標識,HTTP客戶端使用URL定位資源,表示是從資源回傳資料,媒體型別是資源回傳的資料格式。 接下來我們說下HTTP. HTTP協議的系統是一種無狀態的方式,使用請求/ ......

    uj5u.com 2020-09-09 22:07:47 more
  • asp.net core 3.1 入口:Program.cs中的Main函式

    本文分析Program.cs 中Main()函式中代碼的運行順序分析asp.net core程式的啟動,重點不是剖析原始碼,而是理清程式開始時執行的順序。到呼叫了哪些實體,哪些法方。asp.net core 3.1 的程式入口在專案Program.cs檔案里,如下。ususing System; us ......

    uj5u.com 2020-09-09 22:07:49 more
  • asp.net網站作為websocket服務端的應用該如何寫

    最近被websocket的一個問題困擾了很久,有一個需求是在web網站中搭建websocket服務。客戶端通過網頁與服務器建立連接,然后服務器根據ip給客戶端網頁發送資訊。 其實,這個需求并不難,只是剛開始對websocket的內容不太了解。上網搜索了一下,有通過asp.net core 實作的、有 ......

    uj5u.com 2020-09-09 22:08:02 more
  • ASP.NET 開源匯入匯出庫Magicodes.IE Docker中使用

    Magicodes.IE在Docker中使用 更新歷史 2019.02.13 【Nuget】版本更新到2.0.2 【匯入】修復單列匯入的Bug,單元測驗“OneColumnImporter_Test”。問題見(https://github.com/dotnetcore/Magicodes.IE/is ......

    uj5u.com 2020-09-09 22:08:05 more
  • 在webform中使用ajax

    如果你用過Asp.net webform, 說明你也算是.NET 開發的老兵了。WEBform應該是2011 2013左右,當時還用visual studio 2005、 visual studio 2008。后來基本都用的是MVC。 如果是新開發的專案,估計沒人會用webform技術。但是有些舊版 ......

    uj5u.com 2020-09-09 22:08:50 more
  • iis添加asp.net網站,訪問提示:由于擴展配置問題而無法提供您請求的

    今天在iis服務器配置asp.net網站,遇到一個問題,記錄一下: 問題:由于擴展配置問題而無法提供您請求的頁面。如果該頁面是腳本,請添加處理程式。如果應下載檔案,請添加 MIME 映射。 WindowServer2012服務器,添加角色安裝完.netframework和iis之后,運行aspx頁面 ......

    uj5u.com 2020-09-09 22:10:00 more
  • WebAPI-處理架構

    帶著問題去思考,大家好! 問題1:HTTP請求和回傳相應的HTTP回應資訊之間發生了什么? 1:首先是最底層,托管層,位于WebAPI和底層HTTP堆疊之間 2:其次是 訊息處理程式管道層,這里比如日志和快取。OWIN的參考是將訊息處理程式管道的一些功能下移到堆疊下端的OWIN中間件了。 3:控制器處理 ......

    uj5u.com 2020-09-09 22:11:13 more
  • 微信門戶開發框架-使用指導說明書

    微信門戶應用管理系統,采用基于 MVC + Bootstrap + Ajax + Enterprise Library的技術路線,界面層采用Boostrap + Metronic組合的前端框架,資料訪問層支持Oracle、SQLServer、MySQL、PostgreSQL等資料庫。框架以MVC5,... ......

    uj5u.com 2020-09-09 22:15:18 more
  • WebAPI-HTTP編程模型

    帶著問題去思考,大家好!它是什么?它包含什么?它能干什么? 訊息 HTTP編程模型的核心就是訊息抽象,表示為:HttPRequestMessage,HttpResponseMessage.用于客戶端和服務端之間交換請求和回應訊息。 HttpMethod類包含了一組靜態屬性: private stat ......

    uj5u.com 2020-09-09 22:15:23 more
  • 部署WebApi隨筆

    一、跨域 NuGet參考Microsoft.AspNet.WebApi.Cors WebApiConfig.cs中配置: // Web API 配置和服務 config.EnableCors(new EnableCorsAttribute("*", "*", "*")); 二、清除默認回傳XML格式 ......

    uj5u.com 2020-09-09 22:15:48 more
最新发布
  • C#多執行緒學習(二) 如何操縱一個執行緒

    <a href="https://www.cnblogs.com/x-zhi/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2943582/20220801082530.png" alt="" /></...

    uj5u.com 2023-04-19 09:17:20 more
  • C#多執行緒學習(二) 如何操縱一個執行緒

    C#多執行緒學習(二) 如何操縱一個執行緒 執行緒學習第一篇:C#多執行緒學習(一) 多執行緒的相關概念 下面我們就動手來創建一個執行緒,使用Thread類創建執行緒時,只需提供執行緒入口即可。(執行緒入口使程式知道該讓這個執行緒干什么事) 在C#中,執行緒入口是通過ThreadStart代理(delegate)來提供的 ......

    uj5u.com 2023-04-19 09:16:49 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    <a href="https://www.cnblogs.com/huangxincheng/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/214741/20200614104537.png" alt="" /&g...

    uj5u.com 2023-04-18 08:39:04 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    一:背景 1. 講故事 前段時間協助訓練營里的一位朋友分析了一個程式卡死的問題,回過頭來看這個案例比較經典,這篇稍微整理一下供后來者少踩坑吧。 二:WinDbg 分析 1. 為什么會卡死 因為是表單程式,理所當然就是看主執行緒此時正在做什么? 可以用 ~0s ; k 看一下便知。 0:000> k # ......

    uj5u.com 2023-04-18 08:33:10 more
  • SignalR, No Connection with that ID,IIS

    <a href="https://www.cnblogs.com/smartstar/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/u36196.jpg" alt="" /></a>...

    uj5u.com 2023-03-30 17:21:52 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:15:33 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:13:31 more
  • C#遍歷指定檔案夾中所有檔案的3種方法

    <a href="https://www.cnblogs.com/xbhp/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/957602/20230310105611.png" alt="" /></a&...

    uj5u.com 2023-03-27 14:46:55 more
  • C#/VB.NET:如何將PDF轉為PDF/A

    <a href="https://www.cnblogs.com/Carina-baby/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2859233/20220427162558.png" alt="" />...

    uj5u.com 2023-03-27 14:46:35 more
  • 武裝你的WEBAPI-OData聚合查詢

    <a href="https://www.cnblogs.com/podolski/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/616093/20140323000327.png" alt="" /><...

    uj5u.com 2023-03-27 14:46:16 more