0

打开通用类型

public interface ICrudRepository<TEntity, in TKey> where TEntity : class, new()
{

执行

public class EmployeeRepository:ICrudRepository<Employee,int>
{

登记

private static void OnRegistry(ConfigurationExpression iocLib)
        {
            iocLib.Scan(scanner =>
            {
                //bind interfaces with their implementations
                scanner.WithDefaultConventions();

                //scan for types from below projects
                scanner.IncludeNamespace("MyApp.Repository");
                scanner.IncludeNamespace("MyApp.Data");                

                //bind to repository base
                scanner.AddAllTypesOf(typeof(ICrudRepository<,>));

                //bind crudrepository interface with the class that implements it
                scanner.ConnectImplementationsToTypesClosing(typeof(ICrudRepository<,>));
            });

用法

public class HomeController : Controller
    {
        private readonly ICrudRepository<Employee, int> _employeeRepository;

        public HomeController(ICrudRepository<Employee, int> employeeRepository)
        {
            _employeeRepository = employeeRepository;
        }

问题:

接口ICrudRepository在项目 MyApp.Repository 内,实现在项目 MyApp.Data 内。在调用 HomeController 时,我遇到了如下异常。不知道出了什么问题?

<没有为 ICrudRepository Employee, Int32类型注册默认实例并且无法自动确定没有为 ICrudRepository Employee, Int32>指定配置<>

这是我有什么的转储?

===================================================================================================
PluginType           Namespace        Lifecycle     Description                           Name     
---------------------------------------------------------------------------------------------------
Func<TResult>        System           Transient     Open Generic Template for Func<>      (Default)
---------------------------------------------------------------------------------------------------
Func<T, TResult>     System           Transient     Open Generic Template for Func<,>     (Default)
---------------------------------------------------------------------------------------------------
IContainer           StructureMap     Transient     Object:  StructureMap.Container       (Default)
---------------------------------------------------------------------------------------------------
Lazy<T>              System           Transient     Open Generic Template for Func<>      (Default)
===================================================================================================
4

0 回答 0