2017-09-29 12 views
-1

테스트를 실행하는 동안 오류가 발생합니다. 어떻게 해결할 수 있습니까?ASP.NET 보일러 플레이트에서 만족하도록 구성 요소를 만들 수 없습니다.

public class TestAppService : TestAppServiceBase, ITestAppService 
{ 
    private readonly ITestRepository _testRepository; 
    public TestAppService(ITestRepository testRepository) 
    { 
     _testRepository = testRepository; 
    } 
} 

public class TestAppService_Test : TestAppServiceTestBase 
{ 
    private readonly ITestAppService _testAppService; 
    public TestAppService_Test() 
    { 
     _testAppService = Resolve<ITestAppService>(); 
    } 
} 

저장소 :

public class TestRepository : TestRepositoryBase<Test, int>, ITestRepository 
{ 
    private readonly IActiveTransactionProvider _transactionProvider; 
    public TestRepository(IDbContextProvider<TestDbContext> dbContextProvider) 
     : base(dbContextProvider) 
    { 
    } 

    public TestRepository(IDbContextProvider<TestDbContext> dbContextProvider, 
     IActiveTransactionProvider transactionProvider, IObjectMapper objectMapper) 
    : base(dbContextProvider) 
    { 
     _transactionProvider = transactionProvider; 
     ObjectMapper = objectMapper; 
    } 
} 

public interface ITestRepository : IRepository<Test, int> 
{ 
} 

public class TestRepositoryBase<TEntity, TPrimaryKey> : EfCoreRepositoryBase<TestDbContext, TEntity, TPrimaryKey> 
    where TEntity : class, IEntity<TPrimaryKey> 
{ 
    public IObjectMapper ObjectMapper; 
    public TestRepositoryBase(IDbContextProvider<TestDbContext> dbContextProvider) 
     : base(dbContextProvider) 
    { 
    } 
} 

/// <summary> 
/// Base class for custom repositories of the application. 
/// This is a shortcut of <see cref="TestRepositoryBase{TEntity,TPrimaryKey}"/> for <see cref="int"/> primary key. 
/// </summary> 
/// <typeparam name="TEntity">Entity type</typeparam> 
public class TestRepositoryBase<TEntity> : TestRepositoryBase<TEntity, int> 
    where TEntity : class, IEntity<int> 
{ 
    public TestRepositoryBase(IDbContextProvider<TestDbContext> dbContextProvider) 
     : base(dbContextProvider) 
    { 
    } 
} 

오류 :

Test Name: 

ABC.XYZ.Tests.PQR.TestAppService_Test.Should_Create_Test_With_Valid_Arguments 
Test FullName: ABC.XYZ.Tests.PQR.TestAppService_Test.Should_Create_Test_With_Valid_Arguments (20f54c54e5d9f077f4cb38b988ecb8e63e07d190) 
Test Source: C:\Users\viveknuna\source\repos\XYZ\aspnet-core\test\ABC.XYZ.Tests\PQR\TestAppService_test.cs : line 25 
Test Outcome: Failed 
Test Duration: 0:00:00.001 

Result StackTrace: 
at Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency() 
    at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden) 
    at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) 
    at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy) 
    at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy) 
    at Castle.Windsor.WindsorContainer.Resolve[T]() 
    at ABC.XYZ.Tests.PQR.TestAppServiceTestBase..ctor() in C:\Users\viveknuna\source\repos\XYZ\aspnet-core\test\ABC.XYZ.Tests\PQR\TestAppServiceTestBase.cs:line 14 
    at ABC.XYZ.Tests.PQR.TestAppService_Test..ctor() in C:\Users\viveknuna\source\repos\XYZ\aspnet-core\test\ABC.XYZ.Tests\PQR\TestAppService_test.cs:line 17 
Result Message: 
Castle.MicroKernel.Handlers.HandlerException : Can't create component 'ABC.XYZ.Business.Services.PQR.TestAppService' as it has dependencies to be satisfied. 

'ABC.XYZ.Business.Services.PQR.TestAppService' is waiting for the following dependencies: 
- Service 'ABC.XYZ.Business.Repositories.Interfaces.ITestRepository' which was not registered. 

답변

1

Castle.MicroKernel.Handlers.HandlerException : Can't create component 'ABC.XYZ.Business.Services.PQR.TestAppService' as it has dependencies to be satisfied.

'ABC.XYZ.Business.Services.PQR.TestAppService' is waiting for the following dependencies:
- Service 'ABC.XYZ.Business.Repositories.Interfaces.ITestRepository' which was not registered.

가에 DbSet<Test>을 추가하여 DbContext :

public class TestDbContext : AbpDbContext 
{ 
    public DbSet<Test> Tests { get; set; } 

    public TestDbContext(DbContextOptions<TestDbContext> options) 
     : base(options) 
    { 
    } 
} 

당신의 DbContextAutoRepositoryTypes을 추가

[AutoRepositoryTypes(
    typeof(IRepository<>), 
    typeof(IRepository<,>), 
    typeof(TestRepositoryBase<>), 
    typeof(TestRepositoryBase<,>) 
)] 
public class TestDbContext : AbpDbContext 
{ 
    ... 
} 

Target does not implement interface Abp.Domain.Repositories.IRepository`1[[Abp.Localization.Appl‌​icationLanguage, Abp.Zero.Common, Version=2.3.0.0, Culture=neutral, PublicKeyToken=null]] Parameter name: target

등록 TestRepository을 :

Configuration.ReplaceService<IRepository<Test, int>>(() => 
{ 
    IocManager.IocContainer.Register(
     Component.For<IRepository<Test, int>, ITestRepository, TestRepository>() 
      .ImplementedBy<TestRepository>() 
      .LifestyleTransient() 
    ); 
}); 

설명 :

당신이를 주입 할 때, 정의 된대로 IRepository<Test, Int>을 인스턴스화합니다. 그러나 TestRepository은 사용자 정의 TestRepositoryBase<Test, int>을 구현합니다. 따라서 구체적인 클래스를 등록하여 IRepository<Test, Int>을 대체해야합니다.

참조 :

https://aspnetboilerplate.com/Pages/Documents/Entity-Framework-Core#replacing-default-repositories


Missing type map configuration or unsupported mapping. Mapping types: TestDetailsDTO -> Test Abc.Xyz.Business.Dto.Tests.TestDetailsDTO -> Abc.Xyz.Business.Model.Taxes.Test

추가 [AutoMap(Test)] 속성을 TestDetailsDTO에.

그래도 문제가 해결되지 않으면 수동으로 매핑을 구성하려고 : 내 오타를 수정하여이 문제를 해결

public class MyTestModule : AbpModule 
{ 
    public override void PreInitialize() 
    { 
     Configuration.Modules.AbpAutoMapper().UseStaticMapper = false; 
     Configuration.Modules.AbpAutoMapper().Configurators.Add(config => 
     { 
      config.CreateMap<TestDetailsDTO, Test>(); 
      config.CreateMap<Test, TestDetailsDTO>(); 
     }); 
    } 
} 
0

. 윈저의 의존성 삽입은 엄격한 명명 규칙을 따릅니다.

내 인터페이스는

ILeadStatusesAppService

선정되었습니다 그리고 당신은 내가 복수에서 상태 대 단수 상태를 볼 수있는 내 구체적인 목적은 LeadStatusAppService

선정됐다. 그들에게 둘다 복수의 이름 (또는 단수)을 부여한 후에 그것은 효과가있었습니다.