question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DomainServer use dynamic repository

See original GitHub issue

I want to inject dynamic Repository in DomianService, but it didn’t work.

The StockSingleBase.cs and the StockSingleOperationBase.cs are two entities.

IStockSingleManager.cs

public interface IStockSingleManager<TStock,TOperation>: IDomainService where TStock:StockSingleBase where TOperation:StockSingleOperationBase
{
  Task GetAsync(Guid cargoid);
}

StockSingleManager.cs

public class StockSingleManager<TStock,TOperation>: DomainService, IStockSingleManager<TStock,TOperation> where TStock:StockSingleBase where TOperation:StockSingleOperationBase,new()
{
  private readonly IRepository<TStock, Guid> _stockRepository;
  private readonly IRepository<TOperation, Guid> _operationRepository;

  public StockSingleManager(IRepository<TStock, Guid> stockRepository, IRepository<TOperation, Guid> operationRepository)
  {
    _stockRepository = stockRepository;
    _operationRepository = operationRepository;
  }

  public async Task GetAsync(Guid stockId, Guid operationId)
  {
    var stock = await _stockRepository.GetAsync(stockId);
    var operation = await  _operationRepository.GetAsync(operationId);
  }
}

ToolingSingle.cs

public class ToolingSingle:StockSingleBase
{
  public ToolingSingle()
  {
  }
}

ToolingOperation.cs

public class ToolingOperation:StockSingleOperationBase
{
  public ToolingOperation()
  {
  }
}

IToolingSingleAppService.cs

public interface IToolingSingleAppService: IApplicationService
{
 Task<string> TestTask(string aa);
}

ToolingSingleAppService.cs

public class ToolingSingleAppService: ApplicationService,IToolingSingleAppService
{
  private readonly IStockSingleManager<ToolingSingle, ToolingOperation> _stockSingleManager;

  public ToolingSingleAppService(IStockSingleAppBase<ToolingSingle, ToolingOperation> stockSingleManager)
  {
    _stockSingleManager = stockSingleManager;
  }

  public async Task<string> TestTask(string aa)
  {
    return aa;
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Mardoxxcommented, Aug 14, 2018

public ToolingSingleAppService(IStockSingleAppBase<ToolingSingle, ToolingOperation> stockSingleManager)

should this not be public ToolingSingleAppService(IStockSingleManager<ToolingSingle, ToolingOperation> stockSingleManager)

Also I would investigate whether you can register open generics by convention – not sure on this one!


So BasicConventionalRegistrar has the following common implementation for Abp’s conventional dependency registrations

.If(type => !type.GetTypeInfo().IsGenericTypeDefinition)
.WithService.Self()
.WithService.DefaultInterfaces()

Reading here https://github.com/castleproject/Windsor/blob/master/docs/registering-components-by-conventions.md#defaultinterfaces I don’t think that you can register that class by convention this way! Not sure though, give it a test!

0reactions
malimingcommented, Aug 2, 2018

Please take a look at the log. Generally in App_Data/Logs/Logs.txt.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can you have a Repository with dynamic data-sources?
Consider implementing special gateway implementation handling access to multiple other gateways (e.g. by looping as you wrote).
Read more >
DDD - the rule that Entities can't access Repositories directly
There's a bit of a confusion here. Repositories access aggregate roots. Aggregate roots are entities. The reason for this is separation of ...
Read more >
Domain-Driven Design, part 5 — Repository | by Svaťa Šimara
Repositories are persistent collections and allow us to pretend that the system is in-memory. The repository works with complete aggregate and is an...
Read more >
Repository Pattern in ASP.NET Core - Ultimate Guide
A Repository pattern is a design pattern that mediates data from and to the Domain and Data Access Layers ( like Entity Framework...
Read more >
18 Using Variables in the Oracle BI Repository
You can use variables in a repository to streamline administrative tasks and dynamically modify metadata content to adjust to a changing data environment....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found