Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity.MVC5类型IUserService没有可访问的构造函数_C#_Asp.net Mvc_Inversion Of Control_Unity Container - Fatal编程技术网

C# Unity.MVC5类型IUserService没有可访问的构造函数

C# Unity.MVC5类型IUserService没有可访问的构造函数,c#,asp.net-mvc,inversion-of-control,unity-container,C#,Asp.net Mvc,Inversion Of Control,Unity Container,我正在使用存储库模式和 container.RegisterTypes( AllClasses.FromLoadedAssemblies().Where(x => x.Namespace != null && (x.Namespace.Contains("TM.Service") || x.Namespace.Contains("TM.Repository")) ), WithMappings.FromMatch

我正在使用存储库模式和

container.RegisterTypes(
    AllClasses.FromLoadedAssemblies().Where(x =>
         x.Namespace != null && (x.Namespace.Contains("TM.Service") ||
          x.Namespace.Contains("TM.Repository"))
    ),
    WithMappings.FromMatchingInterface,
    WithName.Default,
    WithLifetime.PerResolve
 );
开始时一切都正常,但在运行时更改cshtml文件甚至js文件(开始调试或不调试启动)后,我得到“类型IUserService没有可访问的构造函数。”错误! 这让我抓狂,因为这在更改js或cshtml文件之前就已经起作用了

发生此错误时,重新启动webapp无效,甚至无法生成项目。重新运行webapp的唯一方法是重新构建解决方案

顺便说一句,我的存储库和服务在不同的项目中

更新:

public class UserService : BaseService<User, IUserRepository>, IUserService
    {
        public UserService(IUserRepository repository) : base(repository)
        {
            this.Repository = repository;
        }

}


public interface IUserService : IBaseService<User>
    {

    }

public interface IBaseService<TModel> : IDisposable where TModel : BaseEntity
    {
        object Create(TModel model);
        object Edit(TModel model, string[] blackFields = null, string[] whiteFields = null);
        object Delete(int id);
        IEnumerable GetAll();
        IEnumerable GetGridData();
        IEnumerable<TModel> FindBy(Expression<Func<TModel, bool>> predicate);
        int Count(Expression<Func<TModel, bool>> predicate);
    }


public interface IUserRepository : IBaseRepository<User>
{
}


public interface IBaseRepository<TModel> : IDisposable where TModel : BaseEntity
    {
        TMContext Context { get; set; }

        IDbSet<TModel> Entity { get; set; }

        IQueryable<TModel> All { get; }

        IQueryable<TModel> AllIncluding(params Expression<Func<TModel, object>>[] includeProperties);

        TModel Find(int id);

        IEnumerable<TModel> FindBy(Expression<Func<TModel, bool>> predicate);

        int Count(Expression<Func<TModel, bool>> predicate);

        void Insert(TModel model);

        void Update(TModel model, string[] blackFields = null, string[] whiteFields = null);

        void Delete(int id);

        void Save();

    }
公共类UserService:BaseService、IUserService
{
公共用户服务(IUserRepository):基础(repository)
{
this.Repository=Repository;
}
}
公共接口IUserService:IBaseService
{
}
公共接口IBaseService:IDisposable,其中TModel:BaseEntity
{
对象创建(TModel模型);
对象编辑(TModel模型,字符串[]blackFields=null,字符串[]whiteFields=null);
对象删除(int-id);
IEnumerable GetAll();
IEnumerable GetGridData();
IEnumerable FindBy(表达式谓词);
int计数(表达式谓词);
}
公共接口IUserRepository:IBASERRepository
{
}
公共接口IBaseRepository:IDisposable,其中TModel:BaseEntity
{
TMContext上下文{get;set;}
IDbSet实体{get;set;}
IQueryable所有{get;}
可计量的所有包括(参数表达式[]包括属性);
t模型查找(int-id);
IEnumerable FindBy(表达式谓词);
int计数(表达式谓词);
空洞插入(TModel模型);
无效更新(TModel模型,字符串[]blackFields=null,字符串[]whiteFields=null);
无效删除(int-id);
作废保存();
}
使用方法:

public class UserController : BaseController<User>
    {
        public UserController(IUserService service)
        {
            Service = service;
        }
    }
公共类UserController:BaseController
{
公共用户控制器(IUserService服务)
{
服务=服务;
}
}

我通过在应用程序启动时从服务程序集中初始化一个虚拟类,成功地解决了这个问题。 工作代码看起来像

protected void Application_Start()
    {           
        //For IoC Sake!
        var dummyRepository = new DummyRepository();
        var dummyService = new DummyService();

        ...
    }

您可以显示正在实现IUserService的类吗?@Dismissile,我用类更新了我的问题。tnx