public
Last active

Extensions for StructureMap registrations

  • Download Gist
ExampleRegistry.cs
C#
1 2 3 4 5 6 7 8 9 10 11
using StructureMap;
using StructureMap.Configuration.DSL;
 
public class ExampleRegistry: Registry
{
public ExampleRegistry()
{
For<Interface>().Use<Concrete>()
.Ctor<string>("connectionString").EqualToConnectionString("connectionStringKey");
}
}
StructureMapExtensions.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12
using StructureMap;
using StructureMap.Pipeline;
using System.Configuration;
 
public static class StructureMapExtensions
{
public static SmartInstance<T> EqualToConnectionString<T>(this SmartInstance<T>.DependencyExpression<string> dependencyExpression, string key)
{
string connectionString = ConfigurationManager.ConnectionStrings[key].ConnectionString;
return dependencyExpression.Is(connectionString);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.