Excluding and Including AutoCrud Services

Hi i have managed to exclude AutoCrud Services from auto loading.
But i was wondering if there is a way to load them from a custom plugin.
I managed to make them load if a create Service class that impl. a custom autoquery.
There is another way so i can avoid a service class?
Thanks

After all plugins are loaded the AutoQueryFeature will generate AutoQuery & Crud Services it can find from its LoadFromAssemblies (pre-populated from AppHost.ServiceAssemblies) so your plugin should just be able to add itself in its Register() method, e.g:

public class CustomPlugin : IPlugin
{
    public void Register(IAppHost appHost)
    {
        var dll = GetType().Assembly;
        appHost.ConfigurePlugin<AutoQueryFeature>(c=>c.LoadFromAssemblies.Add(dll));
    }
}

Sorry i will try to explain what i’m trying to achieve
I have a class library on which i have many services declared, but i would like to have them not loaded by default if they are not necessary on a project that use the library.

I thought i could exclude them from autoregistering with ExcludeAutoRegisteringServiceTypes.Add(typeof(CreateTranslation)); but is not working

and the idea is to have multiple Custom Plugin to enable them on a need basis.

I found out that you can register a service manually with appHost.ServiceController.RegisterService(typeof(LanguageService)); how i can achieve the same for autocrud services?

AppHost.ExcludeAutoRegisteringServiceTypes is for excluding auto registering & autowiring ServiceStack Services that would then need to be manually updated.

AutoQuery & AutoCrud Request DTOs are not Services, they’re Request DTO blueprints to generate Services & they only scan which Services need implementing from AutoQueryFeature.LoadFromAssemblies which Auto Query/Crud Services use to generate within a single code generation phase just after all plugins are loaded, i.e. they can’t be adhoc/manually generated.

The existing solution would be to organize your plugins into different assemblies so when you load the plugin you register its assembly as seen in my previous answer.

I’ve just added FilterAutoQueryRequestTypes and FilterAutoCrudRequestTypes in this commit which will let you be able to filter which of the AutoQuery/Crud Request DTOs should have service implementations generated.

Plugins.Add(new AutoQueryFeature {
  FilterAutoQueryRequestTypes = aqDtos => aqDtos.Where(x=> !Exclude(x)).ToList(),
  FilterAutoCrudRequestTypes = acDtos => acDtos.Where(x=> !Exclude(x)).ToList(),
});

It’s currently running through CI & takes 30-45 mins to finish if there weren’t any failed tests. I’ll let you know when this change is on MyGet.

1 Like

This change is now available from v5.9.3+ on MyGet, you’ll need to clear your NuGet packages cache to download the latest version.

$ nuget locals all -clear

Did a quick test and it’s working :slight_smile:
Thanks for the help, this is going to be very useful for me, going from many libs to one it really simplify my project :slight_smile:

1 Like