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.

It should be straightforward to implement query only endpoints without having to implement all members of IResourceService or IEntityRepository and throwing NotImplementedExceptions. This issue is a placeholder until I can work out the design.

Until final release, there are no guarantees on non-breaking changes in pre-release versions

2017-6-11

This work is going to be done on feat/cqrs branch and available as pre-release v2.1.0-alpha1-*

2017-6-30

The current version is available on the unstable branch and can be installed from this MyGet feed. If everything goes well, I plan on wrapping up tests this weekend and pushing to NuGet as a beta.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jasolkocommented, Jun 20, 2017

@williamwong it looks to me like the DbContext is being used specifically in the example implementation of the MyReportService and isn’t required by any base class. Any concrete implementation would be able to define its own dependencies.

I also wonder what the reason is for the endpoint enums over using attributes on the controller?

With the interfaces segregated this way and by defining what methods are supported on the controller is there still a reason to also have separate Cmd/Query Controller/Services?

1reaction
jaredcnancecommented, Jun 30, 2017

@williamwong if your service is implementing multiple interfaces, but not enough to fully implement IResourceCmdService or IResourceQueryService, you first need to inject the service for each implemented interface. Using Autofac, as an example, this is simply:

public class MyResourceService : ICreateService<MyResource>, IDeleteService<MyResource> {
 //...
}

public class Startup {
  public IServiceProvider ConfigureServices(IServiceCollection services) {
    // ...
    builder.RegisterType<MyResourceService>().AsImplementedInterfaces();
    // ...
  }
}

Then in your controller:

public class MyResourcesController : BaseJsonApiController<MyResource, int> {
    public MyResourcesController(
        IJsonApiContext jsonApiContext, 
        ICreateService<MyResource> create,
        IDeleteService<MyResource> delete) 
    : base(
        jsonApiContext, 
        create: create, // <--- pass the services to the base controller using named optional parameters
        delete: delete) { }

    [HttpPost]
    public override async Task<IActionResult> PostAsync([FromBody] MyResource entity) 
        => await base.PostAsync(entity);

    [HttpDelete("{id}")]
    public override async Task<IActionResult>DeleteAsync(int id) 
        => await base.DeleteAsync(id);
}

I haven’t compiled the above code, so please pardon errors

Read more comments on GitHub >

github_iconTop Results From Across the Web

CQRS pattern - Azure Architecture Center
CQRS stands for Command and Query Responsibility Segregation, a pattern that separates read and update operations for a data store. Implementing CQRS in ......
Read more >
CQRS - Martin Fowler
CQRS stands for Command Query Responsibility Segregation. It's a pattern that I first heard described by Greg Young.
Read more >
A Beginner's Guide to CQRS
CQRS is an architectural pattern acronym, standing for Command Query Responsibility Segregation. It divides a system's actions into commands and queries. It is ......
Read more >
What is CQRS (Command and Query Responsibility ...
The Command Query Responsibility Segregation (CQRS) pattern is a design pattern that separates the responsibilities of handling read (query) and write (command) ...
Read more >
Concepts of CQRS
CQRS stands for Command Query Responsibility Segregation. As the name suggests, we split the application into two parts: Command-Side and Query- ...
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