1
0
mirror of synced 2024-11-21 17:03:50 +00:00

[skip appveyor] Added ASP.NET compatibility documentation

This commit is contained in:
Mark van Renswoude 2021-11-07 10:53:45 +01:00
parent 7aab0f86be
commit 68d3a94438
3 changed files with 68 additions and 1 deletions

66
docs/compatibility.rst Normal file
View File

@ -0,0 +1,66 @@
Compatibility
=============
ASP.NET Core
------------
When integrating Tapeti into an ASP.NET Core service, depending on your naming conventions you may run into an issue where ASP.NET tries to register all your messaging controllers as API controllers. This is because by default any class ending in "Controller" will be picked up by ASP.NET.
You can rename your Tapeti controller classes as long as there are no persisted Tapeti Flows for that controller.
Alternatively, you can filter the classes that ASP.NET will register by using a custom ControllerFeatureProvider.
Whitelist ASP.NET controllers
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If all your ASP.NET controllers use the [ApiController] attribute, you can simply whitelist classes which are annotated with that attribute, ensuring the class name is not relevant to ASP.NET:
::
public class APIControllersOnlyFeatureProvider : ControllerFeatureProvider
{
protected override bool IsController(TypeInfo typeInfo)
{
return typeInfo.IsClass && typeInfo.IsPublic && !typeInfo.IsAbstract &&
typeInfo.GetCustomAttribute<ApiControllerAttribute>() != null;
}
}
Blacklist Tapeti controllers
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If instead you want the default ASP.NET behaviour but only exclude Tapeti messaging controllers, you can decorate the default feature provider as follows:
::
public class ExcludeMessagingControllerFeatureProvider : ControllerFeatureProvider
{
protected override bool IsController(TypeInfo typeInfo)
{
return base.IsController(typeInfo) &&
typeInfo.GetCustomAttribute<MessageControllerAttribute>() == null;
}
}
Replace feature provider
^^^^^^^^^^^^^^^^^^^^^^^^
In either case, replace the default ControllerFeatureProvider in the ConfigureServices method of your startup class:
::
public void ConfigureServices(IServiceCollection services)
{
services
.AddControllers()
.ConfigureApplicationPartManager(manager =>
{
var controllerFeatureProvider = manager.FeatureProviders
.FirstOrDefault(provider => provider is ControllerFeatureProvider);
if (controllerFeatureProvider != null)
manager.FeatureProviders.Remove(controllerFeatureProvider);
manager.FeatureProviders.Add(new APIControllersOnlyFeatureProvider());
// or: manager.FeatureProviders.Add(new ExcludeMessagingControllerFeatureProvider());
});
}

View File

@ -74,7 +74,7 @@ A message is simply a plain object which can be serialized using `Json.NET <http
Creating a message controller
-----------------------------
To handle messages you need what Tapeti refers to as a "message controller". It is similar to an ASP.NET MVC controller if you're familiar with those, but it handles RabbitMQ messages instead of HTTP requests.
To handle messages you need what Tapeti refers to as a "message controller". It is similar to an ASP.NET controller if you're familiar with those, but it handles RabbitMQ messages instead of HTTP requests.
All you need to do is create a new class and annotate it with the MessageController attribute and a queue attribute. The name and folder of the class is not important to Tapeti, though you might want to agree on a standard in your team.

View File

@ -7,6 +7,7 @@ Tapeti documentation
introduction
gettingstarted
compatibility
indepth
dataannotations
flow