BaseX Integration

Topics: Core, General, Writing modules
Dec 27, 2013 at 2:24 PM
Hello,

I'm creating module for operating with BaseX (IKVM) databases (creating, opening, etc).
How can i start database server in singleton mode (module onload event or by user activity)?
Do you have any ideas?
Developer
Dec 28, 2013 at 6:37 PM
Edited Dec 28, 2013 at 6:39 PM
I have never used BaseX, but generally:
  • I assume you know about how to write Orchard dependencies (i.e. injectable services). If you don't, please take a look at the docs.
  • If you need to have a singleton (what seems like a fine design for specific DB-access services; NHibernate session factory holder is a singleton too) it's the best to go with Orchard's singletons (not the standard ones where you store the instance in a static field): derive your service's interface from ISingletonDependency. This will make your service a singleton, but tenants will each have a different instance (what is desired most of the time). Of course this also needs that your service should be thread-safe. Note that such singletons, once instantiated (by the IoCC, when you inject it through the ctor of another class for example) live as long as the specific tenant's shell. I.e. once the tenant or the whole application is stopped it will be also terminated (and thus you have to re-start it somehow when the app starts next).
  • Next question is how to start this service. If you need it to be available always and start with Orchard for some reason you could start it from a shell event handler: implement IOrchardShellEvents and start the service from Activated(). This is called when the specific tenant's shell starts. Otherwise you could just inject you service into other, consuming classes and somehow make sure that the DB connection or whatever is initialized before any operation (since your service is a singleton you can store the initialization state in a field).
  • You can of course use this service injected through the ctor from any other class, thus it can also be started from a controller action for example.
  • Your module can't handle its own enabling/installing events (what BTW come from IFeatureEventHandler) since these are raised before it's enabled. But I believe what you're looking for are the mentioned IOrchardShellEvents.
Hope that helps.

BTW may I ask what are you using BaseX for? I also experimented with using multiple databases from Orchard, but with Neo4j.
Dec 28, 2013 at 9:04 PM
This is programmatically s-u-p-e-r! its a integration that I wouldn't mind following its a language tool that I recognize. I've been studying alot of ASP.NET MVC Dependency Injection that's used largely internally mainly for publishing and consuming services between the Ochard.Web host and Orchard packages.
Developer
Dec 28, 2013 at 11:07 PM
@Jerusalem2020J2IL: aren't you afraid of Android Hell?