where to put code that used to be in Application_Start()?

Jul 14, 2010 at 5:20 PM

Apparently, this method no longer gets called...  In there we have code for configuring AutoMapper, and for setting model binders.

 

I know there is a "new" way to do model binders, but...  shouldn't I still be able to do it "the old way" until I get that implemented?

 

Specifically, I have two lines left from my old Application_Start() method that I have been unable to get working:

 

            AutoMapperConfiguration.Configure();

            ModelBinders.Binders[typeof (ModuleEditModel)] = new DerivedModelBinder();

 

I've tried simply popping those into the constructor, right after the call to: ServiceLocatorManager.SetLocatorProvider(() => new StructureMapServiceLocator());

 

And that runs, but..  it seems somehow not to take effect.  In running the application it is clear that AutoMapper isn't happy, doesn't have the mappings it is supposed to have, etc.

 

Please help if you can,

Travis

 

Coordinator
Jul 14, 2010 at 5:33 PM
Hi Travis, I will respond to your previous post on this comment since they're related. :) The TurbineApplication allows you to execute code at start/shutdown of the application. This is done by overriding the Startup and Shutdown methods respectively. So if you want to do custom disposition of objects, you can override the Shutdown method and for any custom for registration before the runtime, use Startup. Here's an example of what the code would look like (the ServiceLocator implementation is irrelevant in this sample) - http://gist.github.com/475708 Does that help out?
Jul 14, 2010 at 8:35 PM
That helps - thanks! But, it does leave the other question still un-answered... The Shutdown() event is sort of like when the Application shuts down, not the end of each request, which is when we were calling the StructureMap code. We've tried to put that code into the ShutdonwContext() method instead, but something is still fishy. We can't get that to run. I'll put more details on that topic in case it can help others in the future. Thanks again! Travis
Coordinator
Jul 14, 2010 at 8:52 PM
Hi Travis, First and foremost, I'm a total idiot. Sorry I miss understood the Application_EndRequest with Application_End! :) Since the TurbineApplication is nothing more than an HttpApplication, you can just implement the Application_EndRequest method directly. See this code sample - http://gist.github.com/476047 In it I'm using the HttpContextScoped option for the IMessageService type.
Jul 14, 2010 at 9:18 PM
Javier - you're about as far from an "idiot" as I can imagine, but thanks :) I see that I can implement the CreateContainer() method and thereby shove things into the ObjectFactory directly (like pre-Turbine). I'm supposing then whatever registrations I make using that method will be disposed in the End_Request() method. That's great. But it fails to take advantage of the IServiceRegistration system. Am I correct in assuming that if I: 1) register something using the IServiceRegistration system, with the vanilla locator.Register<>() commands, and also 2) register something using the CreateContainer() method, using "plain old StructureMap code", that, all of it will "just work" and only the ones registered using method 2 above would be affected by the later call to protected void Application_EndRequest() { ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects(); } ? Mostly meaning, I can use both at the same time - I don't have to move everything into CreateContainer() just to gain the Dispose() functionality? Just the things that need that level of functionality? Thanks so much again, Travis
Coordinator
Jul 14, 2010 at 9:22 PM
This one is a long answer, so how about this? Let me work out a demo project for you that will show what you're describing here and I'll post the link to this board?
Jul 14, 2010 at 9:23 PM
Awesome - thats really going above and beyond - thanks! Travis
Coordinator
Jul 15, 2010 at 3:59 PM
Hi Travis, It's no work at all -- I'm appreciative that you're looking into using MvcTurbine! The sample is here - http://github.com/downloads/jglozano/mvcturbine/SMExtensions.zip The sample creates a new type called StructureMapRegistrator which is an IServiceRegistration however, it uses an IContainer instead of IServiceLocator to leverage the power of the underlying container. Let me know if you need anything else or want to go over the bits.
Jul 19, 2010 at 2:41 AM
Javier - thank you - we are all set now!

Travis


On Thu, Jul 15, 2010 at 11:59 AM, jglozano <notifications@codeplex.com> wrote:

From: jglozano

Hi Travis, It's no work at all -- I'm appreciative that you're looking into using MvcTurbine! The sample is here - http://github.com/downloads/jglozano/mvcturbine/SMExtensions.zip The sample creates a new type called StructureMapRegistrator which is an IServiceRegistration however, it uses an IContainer instead of IServiceLocator to leverage the power of the underlying container. Let me know if you need anything else or want to go over the bits.

Read the full discussion online.

To add a post to this discussion, reply to this email (mvcturbine@discussions.codeplex.com)

To start a new discussion for this project, email mvcturbine@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com