當前位置: 首頁>>代碼示例>>C#>>正文


C# Resolver.LoadDynamicAssemblies方法代碼示例

本文整理匯總了C#中System.Resolver.LoadDynamicAssemblies方法的典型用法代碼示例。如果您正苦於以下問題:C# Resolver.LoadDynamicAssemblies方法的具體用法?C# Resolver.LoadDynamicAssemblies怎麽用?C# Resolver.LoadDynamicAssemblies使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Resolver的用法示例。


在下文中一共展示了Resolver.LoadDynamicAssemblies方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: using

        async void IIsolatedRunner.Run()
        {
            try
            {
                using (_cancellationTokenSource = new CancellationTokenSource())
                {
                    IResolver resolver = new Resolver(new[] {"CH.IoC."});
                    var directories = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath.Split(Path.PathSeparator);
                    resolver.LoadDynamicAssemblies(directories);
                    var log = resolver.Resolve<ILog>();
                    log.Log(1, "IsolatedRunner 1");

                    Type isolatedType;
                    try
                    {
                        isolatedType = AppDomain.CurrentDomain.GetAssemblies()
                                                .SelectMany(x => x.GetTypes())
                                                .FirstOrDefault(
                                                    t =>
                                                    !t.IsInterface &&
                                                    t.GetInterface(typeof (IIsolated).FullName) != null);
                    }
                    catch (Exception ex)
                    {
                        log.Log(2, "IsolatedRunner 5: " + ex);
                        return;
                    }
                    if (isolatedType == null)
                    {
                        log.Log(2,
                                "IsolatedRunner 2: Isolated type not found in any of: " +
                                AppDomain.CurrentDomain.SetupInformation.PrivateBinPath);
                        return;
                    }
                    Debug.WriteLine("IsolatedRunner 9 Running: " + isolatedType.AssemblyQualifiedName);
                    var instance = isolatedType.Assembly.CreateInstance(isolatedType.FullName);
                    var isolated = (IIsolated) instance;
                    if (isolated == null)
                    {
                        log.Log(2, "IsolatedRunner 3: Isolated type not found: " + isolatedType.AssemblyQualifiedName);
                        return;
                    }
                    try
                    {
                        Debug.WriteLine("IsolatedRunner 6: Before Run");
                        await isolated.Run(_cancellationTokenSource.Token);
                        Debug.WriteLine("IsolatedRunner 7: After Run");
                    }
                    catch (Exception ex)
                    {
                        log.Log(2, "IsolatedRunner 4: " + ex);
                    }
                    Debug.WriteLine("IsolatedRunner 8: After Run Catch");
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine("IIsolatedRunner.Run: " + ex);
            }
            _cancellationTokenSource = null;
        }
開發者ID:tanglebones,項目名稱:ch-ioc,代碼行數:62,代碼來源:IsolatedRunner.cs


注:本文中的System.Resolver.LoadDynamicAssemblies方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。