Jeremy D. Miller -- The Shade Tree Developer

Sponsors

The Lounge

Syndication

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Profile’s in StructureMap

This feature has been in StructureMap from the very beginning, but I don’t think that I’ve ever documented it very well.  More docs:

From the very beginning, StructureMap has supported the ability to define a named set of default instances called a "Profile."  The Profile feature was originally meant to be a quick way of switching the connection mode of a smart client application from connected to disconnected modes.  In practice, it's more commonly used as a way to migrate configuration between environments or for creating alternative deployment configurations.  My team uses the Profile feature in our system as a quick way to collapse our entire distributed application into a single AppDomain for easier testing and debugging.  Our "InMemory" profile is defined like this:

            // Using this Profile configures our application to

            // run completely inside a single AppDomain

            // In production the application will consist

            // of the website and 2-3 external windows

            // services

            var repository = new InMemoryRepository();

            CreateProfile(IN_MEMORY_PROFILE, x =>

            {

                x.For<IRepository>().Use(repository);

                x.For<IEventPublishingService>().Use(new InMemoryEventPublishingService(repository));

                x.For<IUserMessagePublisher>().UseConcreteType<InMemoryUserMessageQueue>();

                x.For<IUnitOfWork>().UseConcreteType<InMemoryUnitOfWork>();

            });

In the code, we can switch the application to the in memory mode by calling the SetDefaultsToProfile() method on the Container (or ObjectFactory.Profile = CoreRegistry.IN_MEMORY_PROFILE):

            // This is actual code from a test harness class we use

            // for integration testing

            IContainer container = createContainer(new RuleSet[]{ruleSet});

            container.SetDefaultsToProfile(CoreRegistry.IN_MEMORY_PROFILE);


Posted Sat, Oct 18 2008 4:11 PM by Jeremy D. Miller

[Advertisement]

Comments

David Kemp wrote re: Profile’s in StructureMap
on Thu, Oct 23 2008 10:48 AM

please - for my sanity - remove the apostrophe from "Profiles".

Thanks.

Jeremy D. Miller -- The Shade Tree Developer wrote A Gentle Quickstart for StructureMap 2.5
on Sun, Nov 30 2008 10:56 PM

The most general question I get with StructureMap is “how do I get started?” Personally, I’d recommend

Community Blogs wrote A Gentle Quickstart for StructureMap 2.5
on Sun, Nov 30 2008 11:48 PM

The most general question I get with StructureMap is “how do I get started?” Personally, I’d recommend

A Gentle Quickstart for StructureMap 2.5 - taccato! trend tracker, cool hunting, new business ideas wrote A Gentle Quickstart for StructureMap 2.5 - taccato! trend tracker, cool hunting, new business ideas
on Tue, Dec 2 2008 10:16 AM

Pingback from  A Gentle Quickstart for StructureMap 2.5 - taccato! trend tracker, cool hunting, new business ideas

A Gentle Quickstart for StructureMap 2.5 - taccato! trend tracker, cool hunting, new business ideas wrote A Gentle Quickstart for StructureMap 2.5 - taccato! trend tracker, cool hunting, new business ideas
on Wed, Dec 3 2008 11:04 AM

Pingback from  A Gentle Quickstart for StructureMap 2.5 - taccato! trend tracker, cool hunting, new business ideas

A Gentle Quickstart for StructureMap 2.5 - taccato! trend tracker, cool hunting, new business ideas wrote A Gentle Quickstart for StructureMap 2.5 - taccato! trend tracker, cool hunting, new business ideas
on Thu, Dec 4 2008 11:09 AM

Pingback from  A Gentle Quickstart for StructureMap 2.5 - taccato! trend tracker, cool hunting, new business ideas

Add a Comment

(required)  
(optional)
(required)  
Remember Me?