ApplicationLifetimeObjects, Prism, and Modules

Feb 16, 2011 at 10:00 PM

The user guide (which is really good, BTW) gives example code for handling application lifetimes properly.  Unfortunately, I am lost when trying to figure out how to use the 'SterlingService' class when it resides in a module outside of the shell.  The main question is how can a module, loaded as a ModuleInfo via the ModuleCatalog.xaml, get registered (or otherwise hook) the App's ApplicationLifetimeObjects?


Feb 17, 2011 at 12:39 AM

Thanks, appreciate that.

There are a number of ways to address it. The Sterling service is just a suggestion for a best practice. If you want to access it, you can:

(a) use the singletone pattern, expose a static SterlingService Current and set that, then access it from other modules (just reference the database project).

(b) skip the service and create your own factory/provider class. For example, if you are using Unity or some other IoC container, configure the database instance there (ISterlingDatabaseInstance and your implementation) and use the container to grab the database reference, or

(c) Use the service, and access it by doing:

var instance = (from db in ((App)Application.Current).ApplicationLifetimeObjects where db is ISterlingDatabase select (ISterlingDatabase)db).FirstOrDefault();

That's from the top of my head, haven't tested it but think that should work fine.