Open vallieresc opened 3 years ago
I think the best solution would be to not crash if AddAdmin is not set. I'll have a look at this.
Agree, thanks.
@martijnboland Any development on this solution?
Unfortunately I've been swamped with work the last months, but I'll try to fix this soon. Thanks for the heads up.
I did a quick attempt, but this turns out to be quite difficult. Internally we're using IServiceCollection.AddMvcCore() and that scans all referenced assemblies and automatically adds AppText.Admin as ApplicationPart (which registers a controller) which we did not expect.
I appreciate your effort on this. I don't require this fix at the moment but in the near future. 1 month would be nice but 3 months can be ok.
Found a workaround: when you don't call AddAdmin(), you have to remove the AdminApp application part as well. This is fairly easy (in Startup.cs):
services.AddControllersWithViews()
.ConfigureApplicationPartManager(pm =>
{
var adminAppApplicationPart = pm.ApplicationParts.FirstOrDefault(ap => ap.Name == "AppText.AdminApp");
if (adminAppApplicationPart != null)
{
pm.ApplicationParts.Remove(adminAppApplicationPart);
}
});
Hmmm simple but difficult to implement in my case. I encapsulate AppText in a library with its own startup.cs. The client application has its startup.cs with the services.AddControllersWithViews(). Each app would have to add this parameter. I'd like to manage this in the library. It's a good start, let me know if you find anything else.
If the AppText.AdminApp reference is added but no .AddAdmin() is set the result is InvalidOperationException: Unable to resolve service for type 'AppText.AdminApp.Configuration.AppTextAdminConfigurationOptions' while attempting to activate 'AppText.AdminApp.Controllers.AdminController'.
My setup has options in the appsettings file for the dev to disable the admin feature in their environment so it would be great to be able to disable admin for security reasons. Not sure what the best approach would be for this? Removing the Admin package is a way but when releasing the app in other environments it's not great. A quick appsettings change would be ideal for us = no .AddAdmin() set or .AddAdmin(o => o.Enable = false).