泛型中的隐式转换失败

时间:2012-07-30 10:06:22

标签: c# generics

    public class ExternalUserService : ServiceBase<ExternalUser>, IServiceBase<ExternalUser>, IDisposable
        {
            public ExternalUserService():base()
            {enter code here

            }

            public ExternalUserService(IBusinessEntityMap entityMap,string ConnectionString)
            {
                repository = new BusinessModelRepository(typeof(ExternalUserMap), ConnectionString);
        }
    }

 [ServiceContract(ConfigurationName = "IServiceBase", Namespace = "http://xyz.com")]

    public interface IServiceBase<TEntity> where TEntity : BusinessEntityBase<TEntity>, new()
    {
        [OperationContract]
    }

 [DataContract(IsReference = true)]
    public class ExternalUser : BusinessEntityBase<ExternalUser>
    {
//some entity work
        }
  

我正在尝试编写服务主机工厂,以便我可以拥有单个主机并基于实体。这样我就可以拥有一台主机。

之类的东西
<%@ ServiceHost Factory="Service.BaseServiceFactory`1[BusinessEntityBase<ExternalUser>,IServiceBase<ExternalUser>,ExternalUser]" 

Language =“C#”Debug =“true”Service =“某些通用服务”%&gt;

public class BaseServiceFactory<x,y,z> : ServiceHostFactory
       where x : BusinessEntityBase<y>,new()
        where z : IServiceBase<x>
        where y : class,new()
    {

        protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {


            ServiceHost host = new ServiceHost(serviceType, baseAddresses);
            ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(z), new BasicHttpBinding(), "");

            return host;
        }
    }

 public abstract class BusinessEntityBase<TEntity> : IBusinessEntity<TEntity>
        where TEntity : class, new()
    {
}

我在第10行得到以下错误(B​​aseServiceFactory类的声明)。

类型'x'不能用作泛型类型或方法'Service.IServiceBase'中的类型参数'TEntity'。没有从'x'到'BusinessModel.BusinessEntityBase'的隐式引用转换。 D:\ Service \ BaseServiceFactory.cs 10 18 Security.Service

0 个答案:

没有答案