Unity:无法解析类型名称或别名 x。请检查您的配置文件并验证此类型名称

Unity: The type name or alias x could not be resolved. Please check your configuration file and verify this type name

错误代码

The type name or alias UnitOfWorkFactory could not be resolved. 
Please check your configuration file and verify this type name.

我正在抓取 google 结果/尝试调试 2 天,但我还没有找到任何解决方案。

提到 "ApplicationService" 正在解决。

下面是我的代码,希望足够了。如果还有其他 file/info 被我遗漏了,我深表歉意,我会立即编辑 post。

IApplicationService.cs

using System.Collections.Generic;
using Abc.Project.Domain.Model.DTO;

namespace Abc.Project.Application.Interfaces
{
    public interface IApplicationService
    {
        void AddFile(FileDTO fileDTO);
    }
}

ApplicationService.cs

using System.Collections.Generic;
using AutoMapper;
using Microsoft.Practices.Unity;
using Abc.Project.Application.Interfaces;
using Abc.Project.Domain.Model.DTO;
using Abc.Project.Domain.Model.Poco.Entities;
using Abc.Project.Domain.Repository.UnitOfWork;
using Abc.Project.Domain.Unity;

namespace Abc.Project.Application.Services.Global
{
    public class ApplicationService : IApplicationService
    {
        public void AddFile(FileDTO fileDTO)
        {
            File file = new File
            {
                Id = fileDTO.ID,
                FileObs = fileDTO.FileObs,
                Ind = fileDTO.Ind,
                Levels = fileDTO.Levels,
            };

            using (var uow = IoC.Container.Resolve<IUnitOfWorkFactory>().Create())
            {
                uow.Context.File.Add(file);
                uow.Commit();
            }
        }
    }
}

IUnitOfWorkFactory.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Abc.Project.Domain.Repository.UnitOfWork
{
    public interface IUnitOfWorkFactory
    {
        IUnitOfWork Create();
    }
}

UnitOfWorkFactory.cs

using System.Data;
using System.Reflection;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Tool.hbm2ddl;
using Abc.Project.Domain.Repository.UnitOfWork;

namespace Abc.Project.DataAccess.NHibernate.UnitOfWork
{
    public class UnitOfWorkFactory : IUnitOfWorkFactory
    {
        private static ISessionFactory CreateSessionFactory()
        {
            return Fluently.Configure()
                .Database(MsSqlConfiguration.MsSql2008
                .ConnectionString(c => c.FromConnectionStringWithKey("FilesDB"))
                )
                .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
                .ExposeConfiguration(cfg => new SchemaExport(cfg)
                .Create(false, false))
                .BuildSessionFactory();
        }

        public IUnitOfWork Create()
        {
            UnitOfWork UnitOfWork = new UnitOfWork(CreateSessionFactory().OpenSession());
            UnitOfWork.BeginTransaction(IsolationLevel.ReadCommitted);
            return UnitOfWork;
        }
    }
}

App.config

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>

  </configSections>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <connectionStrings>
    <add name="FilesDB" providerName="System.Data.SqlClient" connectionString="server=SP2010;database=FilesDB;User ID=sa;Password=password;"/>
  </connectionStrings>
  <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <typeAliases>
      <!-- Lifetime manager types -->
      <typeAlias alias="singlecall" type="Microsoft.Practices.Unity.TransientLifetimeManager, Microsoft.Practices.Unity"/>
      <typeAlias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity"/>
      <typeAlias alias="external" type="Microsoft.Practices.Unity.ExternallyControlledLifetimeManager, Microsoft.Practices.Unity"/>
      <typeAlias alias="percall" type="Abc.Project.Domain.Unity.StaticPerCallLifeTimeManager, Abc.Project.Domain.Model"/>

      <!-- SERVICE APPLICATION INTERFACES-->
      <typeAlias alias="IApplicationService" type="Abc.Project.Application.Interfaces.IApplicationService, Abc.Project.Application.Interfaces"/>

      <!-- DOMAIN INTERFACES-->
      <typeAlias alias="IUnitOfWorkFactory" type="Abc.Project.Domain.Repository.UnitOfWork.IUnitOfWorkFactory, Abc.Project.Domain.Repository"/>

      <!-- CONCRETE CLASSES-->

      <!-- SERVICE APPLICATION-->
      <typeAlias alias="ApplicationService" type="Abc.Project.Application.Services.Global.ApplicationService, Abc.Project.Application.Services"/>

      <!--DATA ACCESS-->
      <typeAlias alias="UnitOfWorkFactory" type="Abc.Project.DataAccess.NHibernate.UnitOfWork.UnitOfWorkFactory, Abc.Project.DataAccess.NHibernate"/>

    </typeAliases>
    <containers>
      <container>
        <!--<extension type="Interception" />-->
        <types>

          <type type="IApplicationService" mapTo="ApplicationService">
            <lifetime type="singlecall"/>
          </type>
          <type type="IUnitOfWorkFactory" mapTo="UnitOfWorkFactory">
            <lifetime type="singleton"/>
          </type>

        </types>
      </container>
    </containers>
  </unity>

  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="Abc.Project.WcfService.WcfServiceAspNetAjaxBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="metadataAndDebug">
          <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
          <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <services>
      <service name="Abc.Project.WcfService.WcfService" behaviorConfiguration="metadataAndDebug">
        <endpoint address="" behaviorConfiguration="Abc.Project.WcfService.WcfServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="Abc.Project.WcfService.WcfService"/>
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

我该如何解决这个问题? 英语不是我的母语;请原谅输入错误。

改用 <alias> 元素。这是 Unity 配置架构的 link

<unity>
   <alias alias="IUnitOfWorkFactory" type="Abc.Project.Domain.Repository.UnitOfWork.IUnitOfWorkFactory, Abc.Project.Domain.Repository" />

   <alias alias="UnitOfWorkFactory" type="Abc.Project.DataAccess.NHibernate.UnitOfWork.UnitOfWorkFactory, Abc.Project.DataAccess.NHibernate"/>

</unity>

<typeAlias>-Element 已过时并且不再支持取决于您的 Unity 版本。

未引用 UnitOfWorkFactory 的程序集