2

I'm very new to DotNetNuke module development but fairly well versed in StructureMap as an IoC container and the concepts of IoC and Dependency Injection.

I'm following the DNN module tutorial vids here - http://www.dotnetnuke.com/Resources/Video-Library.aspx - but I can't quite figure out where I would do my StructureMap initialization.

Within the framework of DNN module development, where do I do this?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Chris Hawkins
  • 808
  • 1
  • 7
  • 22

1 Answers1

3

There isn't a good place to do one time initialization like that in DotNetNuke. DNN doesn't give a clean hook into the Application_Start event.

One approach that we've taken is to implement an HttpModule that does the initialization, with a lock to ensure it just happens once. Ian Robinson had an example of that in his Beer Collection MVP sample module, but appears to have torn it out somewhat. One problem with this approach is that it requires a request through the pipeline to setup everything. We've seen cases where a scheduled task (which doesn't run in the context of a request) was able to start without this initialization, and then blow up because it didn't have any dependencies.

bdukes
  • 152,002
  • 23
  • 148
  • 175
  • Would doing it in the OnInit method of PortalModuleBase work? – Chris Hawkins Feb 01 '13 at 17:35
  • By `PortalModuleBase`, do you mean your own class which inherits from it (i.e. avoiding modifications to DNN core code)? Yeah, that should work, I'd think, so long as you remember it for anything that's not a module control (e.g. extra aspx pages, http modules/handlers, providers, etc). – bdukes Feb 01 '13 at 20:50
  • Yes, overriding OnInit i.e.: public class MyModuleBase : DotNetNuke.Entities.Modules.PortalModuleBase { protected override void OnInit(System.EventArgs e) { base.OnInit(e); var registry = new MyModuleRegistry(); ObjectFactory.Initialize(c => c.AddRegistry(registry)); ObjectFactory.AssertConfigurationIsValid(); } } – Chris Hawkins Feb 01 '13 at 21:22
  • 1
    Not sure it initializing multiple times is a problem or not; you may want to wrap that in a `lock` to ensure it only happens once. – bdukes Feb 01 '13 at 22:22