Resolution of objects using PluginManager in a Package

58 views
Skip to first unread message

Rusty Swayne

unread,
Apr 17, 2014, 6:00:35 PM4/17/14
to umbra...@googlegroups.com
I have been working with the newly publicized PluginManager in Umbraco.Core to try to resolve 3rd party plugins to the Merchello package.  Basically, we are using the PluginManager to resolve various providers (shipping, payment, tax).  The problem I am facing (I think) is I need to restart the application pool after I upload a package containing a provider.  At least that is what I've been doing to get them to kick.  

It may be the Resolution is frozen by the time a package binary is dropped into the bin folder when a new package is uploaded containing something we want to resolve - not sure how to test for that.  Another possibility is that I may be registering my resolvers in wrong handler - currently I'm using the ApplicationInitialized.

There are a bunch of ways to work around the issue, package actions etc. but I was hoping there was something I could change so that each and every provider would not have to implement little package actions.

Shannon Deminick

unread,
Apr 19, 2014, 9:45:03 PM4/19/14
to umbra...@googlegroups.com
Need a little more info here. What do you mean by "I upload a package containing a provider" ? Is this a DLL? If you add a DLL to the /bin the app will automatically restart. Can you post some code about "registering my resolvers in wrong handler - currently I'm using the ApplicationInitialized" it's not clear what you are actually doing there.

Rusty Swayne

unread,
Apr 21, 2014, 12:58:48 PM4/21/14
to umbra...@googlegroups.com
Yep - sorry Shannon.  Serves me write trying to write something up at the end of the day.

I have package (Merchello) installed in Umbraco which includes a little ApplicationEventHandler class

    public class GatewayResolutionApplicationEventListener : ApplicationEventHandler
    {
        protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            base.ApplicationStarting(umbracoApplication, applicationContext);
 
            PaymentGatewayProviderResolver.Current = new PaymentGatewayProviderResolver(() => PluginManager.Current.ResolveTypes<PaymentGatewayProviderBase>());
            TaxationGatewayProviderResolver.Current = new TaxationGatewayProviderResolver(() => PluginManager.Current.ResolveTypes<TaxationGatewayProviderBase>());
            ShippingGatewayProviderResolver.Current = new ShippingGatewayProviderResolver(() => PluginManager.Current.ResolveTypes<ShippingGatewayProviderBase>());
        }
}

The solvers are really basic sub classes of LazyManyObjectResolverBase

    internal sealed class PaymentGatewayProviderResolver : LazyManyObjectsResolverBase<PaymentGatewayProviderResolverPaymentGatewayProviderBase>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PaymentGatewayProviderResolver"/> with an intial list of PaymentGatewayProvider types
        /// </summary>
        /// <param name="providers">The list of PaymentGatewayProviders</param>
        internal PaymentGatewayProviderResolver(Func<IEnumerable<Type>> providers)
            : base(providers)
        { }
 
        public IEnumerable<Type> ProviderTypes
        {
            get { return InstanceTypes; }
        }
 
    }

We want to be able to allow other package developers be able to build extensions to Merchello as Umbraco packages and add them to Umbraco via the standard Umbraco install process.  If the package (the extension package) contains a binary with has a sub class of PaymentGatewayProviderBase for example, we are trying to get our resolvers identify the class and add it to our list of "Payment Providers".  This works beautifully if we simply drop the DLL containing the class to be resolved into the bin file, but our resolvers fail to resolve the class if it is included in a package and added through Umbraco - albeit pulling the dll out of the bin directory and immediately dropping it back in does force the resolution.

Also, in my previous description, I eluded to restarting the application pool corrects the issue.  This actually turns out not to be true.  Restarting IIS does not do it either - we have to remove the DLL from the bin and drop it back in or delete the PluginCache and restart the application pool.  

Is there a way to refresh the PluginCache?
 

Shannon Deminick

unread,
Apr 21, 2014, 7:57:11 PM4/21/14
to umbra...@googlegroups.com
Typically you should be creating your resolvers in the ApplicationInitialized method, the ApplicationStarting method is used to modify/replace resolvers before resolution is frozen and the ApplicationStarted is used after resolution is frozen in order to return item(s) from the resolvers. See: http://our.umbraco.org/Documentation/Reference/Events/application-startup#UsingApplicationEventHandlertoregisterevents

I'm not sure if that will solve your problem though - which does seem like an odd one since we restart the application pool and the whole application when you install a package from within Umbraco and of course if there is a DLL in the package it will automatically restart the app pool anyways. The PluginCache is ignored when we detect a hash change between what was previously in the /bin folder which has been working successfully since 6.x for all package installs. 

Let me know if creating your providers in ApplicationInitialized fixes anything, otherwise we'll need to investigate why it's not picking up the types in the installed package. There's a folder: ~/App_Data/PluginCache that contains two files, one which is the calculated hash and the other is the cached types found. Before you install your package you can check what the hash is in the hash file and then check that it has changed after you install. You can also inspect the cache file to see what's been found.

Shannon Deminick

unread,
Apr 23, 2014, 6:56:12 AM4/23/14
to umbra...@googlegroups.com
Hey Rusty, 

Your last reply was to the digest email :)
In any case, you can ping me on hangouts or skype and can walk me through the issue you're having, you definitely shouldn't need to clear out any plugin cache files, I have a feeling this is an issue with an expected chain of events that isn't firing in the expected manner.
Reply all
Reply to author
Forward
0 new messages