I have a largish application that is becoming ServiceStack based. This application is customized heavily for different clients. In order to maximize maintainability and reuseability, I'm trying to make the backend code more modular. This is new to me. We'd like to have two types of modular extensions: (1) Feature extensions where we build out new features with associated new service requests (data models, etc..) custom for a client and (2) integration extensions that perform additional logic that is client specific after performing our core/base logic for existing service requests. We target .NET Core 2.1, planning to move to 3 soon.
I am not trying to split into microservices--I just want to move my services into separate assemblies so that I can deploy the core application to a customer along with a folder with their customer specific features/extensions. I'd like to load these extension and integration services dynamically from a "plugins" directory. We hope to reuse some of these extensions between customers.
For the feature extensions, I'd like ServiceStack to autowire them and be able to declare routes with attributes on my ServiceModels in the new assemblies like I do presently (love ServiceStack :-).
For the integration extensions, I'd like to be able to have these respond to the same requests as my core application (potentially have a chain of services responding to the request). I've thought about doing these by having an interface for each type of integration extension and have the core/base application look for what extensions are registered with that interface and call them from the core service.
I am looking for advice on the best way to implement these goals with ServiceStack. I have been reading about modularizing services and about plugins with ServiceStack and also looking at project like MEF and ExtCore and this blog post (but it seems very dated). But I am a little confused. Does ServiceStack have out of the box functionality for this or do I need to look at integrating something like MEF / ExtCore? I like the idea of encapsulating services inside of ServiceStack PlugIns using IPlugin, but it seems like then I have to explicitly register the services in the plugin then rather than let ServiceStack autowire them--is that true? Do I need to override CreateServiceController and use MEF or other composition tool here?
Any help understanding all this or advice is much appreciated.
Have a look at the "No touch" Host Configuration in latest v5.5, you can implement
IPreConfigureAppHost to split your AppHost configuration across multiple files which are normally run on Startup.
If you want to register an additional Service Assembly in a plugin you can implement
IPreConfigureAppHost which will run before the Services are auto-wired thereby you can register additional Service Assemblies you want auto registered there, e.g:
public class ConfigureContactsServices : IPreConfigureAppHost
public void Configure(IAppHost host) =>
Keep in mind that ServiceStack configuration should be treated as immutable after Startup, e.g. it's not ThreadSafe to dynamically register/unregister Services or IOC dependencies at runtime.