This project is read-only.

INotificationProvider error

Topics: Writing modules
Aug 1, 2011 at 6:04 PM
Edited Aug 1, 2011 at 6:05 PM

I am using the INotificationProvider to send a message to a user about some items they need to be aware about during their visit to the admin section of our site.  Inside this class that implements INotificationProvider, it calls a service method to query those items and generate the message to the user.  This all works great, but I'm running into an issue when installing the module.   Because the migration hasn't run yet, the notification errors out.

Now, it should be said that this is all in development, and I came about this error when I had to add a field to my migration/models and blew away the migration record and table that got created so that I could just re-run the migration to have it pick up my new field.  Yet, I would assume I would still see this same issue whether or not it was a brand new module or just one that was already installed and had its migration record deleted...

So, is there a way to conditionally run the INotificationProvider code (maybe this is already done if the module is not enabled, making this a non-issue?)? I noticed some of the built-in stuff that uses INotificationProvider didn't have any special logic to account for this, so obviously I'm just missing something in this process.  Thanks...

Aug 1, 2011 at 7:48 PM

Did you try decorating the class with an OrchardFeature attribute?

Aug 1, 2011 at 7:50 PM

I didn't know that existed, but I'll try that. What exactly does that do?

Aug 1, 2011 at 7:53 PM

The class you decorate it with will only be registered with Autofac if the feature in question is enabled. So for all practical purposes, your class is invisible to Orchard unless the feature is enabled.

Aug 1, 2011 at 7:55 PM

Perfect. This doesn't solve the issue of it happening when I manually blow away the migration, but when I do finally contribute this back to the community, it will work for someone who is installing it for the first time...thanks!

Aug 3, 2011 at 9:05 PM

I  tried adding OrchardFeature attribute to the class, and even though the module for this is enabled, it wasn't running the GetNotifications code...

Aug 3, 2011 at 9:08 PM

So that's a new problem, right? It was working without the attribute wasn't it? Are you sure you used the right feature id in the attribute? Is none of the code getting hit? Maybe put a breakpoint in the constructor?

Aug 3, 2011 at 9:10 PM

I just chose my own feature Id, I didn't know it had to match...let me try that :)

Aug 3, 2011 at 9:14 PM

Yes, that worked.  I thought that was a name that would show up in the feature list, I didn't know that was tying it to an existing feature.

Aug 3, 2011 at 9:14 PM

Well, I mean with the string for the attribute...

Aug 10, 2011 at 7:36 PM

Small update on this, it seems like it's still doing something even though I added the OrchardFeature tells me:

Invalid object name 'MyModule_MyModuleRecord

Basically, the query that gets run inside that notification provider to check for existing notifications to display is getting run, but the migration hasn't run yet so it can't find the table for my record...

Aug 10, 2011 at 8:23 PM

Did you annotate *all* the classes involved in the feature?