Microsoft.Practices.Unity.dll中发生了类型为'Microsoft.Practices.Unity.ResolutionFailedException'的未处理异常

时间:2019-11-28 15:30:13

标签: c#

我想知道是否有人可以帮助我? 我从一个不在这里的开发人员那里选择了一个项目,我需要重建他的一个应用程序。

该应用程序将成功构建,但是如果我尝试运行它,则会出现以下错误:

  

类型的未处理异常   “ Microsoft.Practices.Unity.ResolutionFailedException”发生在   Microsoft.Practices.Unity.dll

     

其他信息:依存关系的解析失败,键入=   “ App.MainForm”,名称=“(无)”。

程序在这一行中断:

_mainForm = container.Resolve<MainForm>();

我拥有的全部代码如下:

    namespace Refunds
{
    internal class RefundApplicationContext : ApplicationContext
    {
        private TerritoryForm _territoryForm;
        private MainForm _mainForm;
        private IRefundProcessorConfig _config;

        public RefundApplicationContext()
        {
            using (IUnityContainer container = new UnityContainer())
            using (ContainerControlledLifetimeManager manager = new ContainerControlledLifetimeManager())
            {
                container
                    .AddNewExtension<BuildTracking>()
                    .AddNewExtension<LogCreation>()
                    .RegisterType<MainForm>()
                    .RegisterType<IRefundProcessor, RefundProcessor>()
                    .RegisterType<IRefundCollection, RefundCollection>()
                    .RegisterType<ISepaValidation, SepaValidation>()
                    .RegisterType<IBankValidationConfig, BankValidationConfig>()
                    .RegisterType<IBankValidation, BankValidation>()
                    .RegisterType<IRefundProcessorConfig, RefundProcessorConfig>(manager)
                    .RegisterType<ISalesLedgerBrokerFacade, SalesLedgerBrokerFacade>()
                    .RegisterType<IPurchaseLedgerRestClientHelper, PurchaseLedgerRestClientHelper>()
                    .RegisterType<ISystemKeyRestClientHelper, SystemKeyRestClientHelper>()
                    .RegisterType<ISepaRestClientHelper, SepaRestClientHelper>()
                    .RegisterType<IPaymentHelper, PaymentHelper>()
                    .RegisterType<IPdfDocument, PdfDocument>()
                    .RegisterType<IStringCipher, StringCipher>()
                    .RegisterType<IRefundFactory, RefundFactory>()
                    .RegisterType<IFileHelperEngine<Refunds.Implementation.Csv.Refund>, FileHelperEngine<Refunds.Implementation.Csv.Refund>>(new InjectionConstructor())
                    .RegisterType<IDirectDebitBusinessServiceFacade, DirectDebitBusinessServiceFacade>();

                _territoryForm = container.Resolve<TerritoryForm>();
                _mainForm = container.Resolve<MainForm>();
                _config = container.Resolve<IRefundProcessorConfig>();
            }


            _territoryForm.FormClosed += new FormClosedEventHandler(_territoryForm_FormClosed);
            _mainForm.FormClosed += new FormClosedEventHandler(_mainForm_FormClosed);

            _territoryForm.Show();

            _mainForm.Show();
        }

        private void _territoryForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (_territoryForm.DialogResult == DialogResult.OK)
            {
                _config.Territory = _territoryForm.Territory;

                _mainForm.Show();
            }
            else
                ExitThread();
        }

        private void _mainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            ExitThread();
        }
    }
}

0 个答案:

没有答案