MediatR | Simple , unambitious mediator implementation in .NET | Reactive Programming library
kandi X-RAY | MediatR Summary
kandi X-RAY | MediatR Summary
Simple, unambitious mediator implementation in .NET
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of MediatR
MediatR Key Features
MediatR Examples and Code Snippets
Community Discussions
Trending Discussions on MediatR
QUESTION
I have a project that is separated into three layers:
- An API, which sends MediatR queries and commands to the application layer.
- A class library of application logic that uses fluent validation.
- A class library of domain objects.
Originally the domain objects class library was locally referenced by the application layer, which was then referenced by the API layer.
Domain > Application > API
Recently, I moved the domain layer to a Nuget Package, so that it can be used by other projects as well as this one. However, since moving it I'm getting 400 Bad request validation errors when sending requests to my API.
...ANSWER
Answered 2022-Apr-16 at 10:56When you moved your domain layer into a separate project (NuGet) you might have accidentally switched on NRT (see docs) and that's why Fluent Validation is being more strict (which is a good thing).
Check if the validation message are actually true positives. If they're not helpful, keep NRT enabled but relax your validation rules.
QUESTION
In the Startup.ConfigureServices I'm adding MassTransit configuration
...ANSWER
Answered 2022-Apr-07 at 12:41IRequestClient
is scoped, and you're trying to resolve it without a scope.
Also, your bus configuration is seriously outdated, change:
config.AddBus(provider => Bus.Factory.CreateUsingRabbitMq();
to the supported syntax:
config.UsingRabbitMq((context, cfg) => {});
QUESTION
i have communication problem while retrieving data from the database
ContractDataService
...ANSWER
Answered 2022-Apr-03 at 23:40Add
QUESTION
I am building Web API backend for multitenant, .NET 6 based, application and I have encountered an architectural problem which drives me crazy since last couple of weeks, so I would much appreciate ANY hints and advices.
Whole solution is build in classic Clean Architecture (layers: API, Domain, Application, Infrastructure, Shared), which was't the greatest idea I suppose, but I'm affraid it is irreversible by now. Anyway, I would like to make an effort to save all I have created so far.
In the application I have 2 databases (with Entity Framework in the code behind):
Database A: Tenant users scope - with TenantId field in each table for RLS mechanizm implemented on the SQL level to prevent inter-tenant data leaks
Database B: Internal users scope - no RLS mechanism
The problem is both databases share great amount of common structures and logic.
Simplified example of current models (both database and domain):
Database A:
ANSWER
Answered 2022-Mar-23 at 11:06This way I'm creating a lot of code duplication. I do not want to create common interfaces for those classes because I think this may kill the application's development in some point in the future (Models may become a little bit different anytime).
If you have too much duplication, you are right in thinking you should merge your code. If both model should be able to have common code, and specific code, then the solution to your problem is probably polymorphism.
I would suggest to have two new classes Domain.TenantEmployee
and Domain.InternalEmployee
both inheriting from an abstract Domain.Employee
. You can put common behavior in the parent class, and specific one in the child ones.
Then your infrastructure layer can convert Domain.TenantEmployee
from/to DatabaseA.TenantEmployee
and Domain.InternalEmployee
from/to DatabaseB.InternalEmployee
.
QUESTION
I have an Web API application that uses both Mediatr and Autofac.
In my Startup.ConfigureServices method I have:
...ANSWER
Answered 2022-Mar-18 at 22:28IMediatr
is still available because you (also) register it via below call in your code.
QUESTION
I'm building an API that will handle http calls that perform much work immediately.
For example, in one controller, there is an action (Post
request) that will take data in the body, and perform some processing that should be done immediately, but will last for about 1 to 2 minutes.
I'm using CQRS, with Mediatr, and inside this post request, I call a command to handle the processing.
Taking this into consideration, I want the post request to launch the command, then return an Ok to the user though the command is still running in the background. The user will be notified via email once everything is done.
Does someone know any best practice to accomplish this?
Though I'm using MediatR, sending the request to the handler, the call is not executed in parallel.
...ANSWER
Answered 2022-Feb-22 at 13:22I would handle API calls that takes some time separately from calls that can be completed directly.
when I do API calls that takes time, I queue them up and process them on the backend.
a typical API call can look something like this:
QUESTION
I am using MediatR. Requests are decorated like so
...ANSWER
Answered 2022-Feb-05 at 13:16The answer was (unsurprisingly) that I needed to wrap the calls with other calls rather than use the MediatR pipeline. So I created an IDispatcher interface.
In Program.cs
...
QUESTION
As per Command Query Separation principle, commands should return void.
I am using MediatR Command Request Handler to create an entity as follows. So how can I get back the created entity?
...ANSWER
Answered 2022-Feb-04 at 19:02If you really want the created value back, you can change your request / handler to return it:
QUESTION
I have a solution created in .NET 6.0 using Visual Studio 2022 which has many projects.
Each project has so many nuget package references in the .csproj file as below.
Is it possible to manage all nuget packages in a single location / globally in the solution (instead of for each project)?
This will make sure all projects in the solution are using the same version of the package (no more version conflicts between the projects for the same nuget package).
Updating the package once at the central location will ensure all projects are referring to the same updated version. No need to update the package for every project.
Thanks for your help.
...ANSWER
Answered 2022-Feb-02 at 09:41There's a few approaches to doing this, though none are perfect.
Manually, with a .targets fileHave a .targets file with all the packages you reference but use instead of
Include=
. Include this in your Directory.Build.targets file, so that it will be applied at the end of each project file.
The biggest downside to this is that any time a new PackageReference is added to any project, you'll need to also remember to update the .targets file to include an entry to update that package version.
This will ensure that all of your
entries will unify to the same versions. However, it does not impact transitive references, i.e. if you have Project1 -> Package1 -> Package2, but only have a PackageReference to Package1, you won't be able to affect the referenced version of Package2. This may create conflicts if Project2 -> Package2 at a different version than what Package1 references.
Use the Central Package Versions MSBuild SDK (CPV)
The manual process can be error-prone, so there's an SDK to help make the process smoother. You can find it at Central Package Versions. This also provides enforcement that users do not specify a version in the project (because they should be using the central one instead!) so it will be more consistent than using the manual technique.
This also does not resolve transitive dependency issues in any way.
Use Nuget Central Package Version Management (CPVM)
This is the NuGet team's solution (in progress) to the issue. You can find the documentation at Centrally managing NuGet package versions. The feature is still in preview, the basic behaviors seem pretty firm but may change in the future as the design is refined.
Have a file named Directory.Packages.props in your root folder, and enable the feature (opt-in is required because it's still in preview) by adding:
QUESTION
In MediatR's documentation is said:
Containers that support generic variance will dispatch accordingly. For example, you can have an
INotificationHandler
to handle all notifications.
But in my case it doesn't work. My question is how to make it working contravariant, so I don't have to create specific handler for each notification type?
I have hierarchy of models like this:
...ANSWER
Answered 2022-Jan-26 at 14:07This is an issue with your container, not MediatR or the DI extensions library. You'll want to register an open generic if you want the variance to kick in. Something like:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install MediatR
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page