Wiki

Clone wiki

StructureMapWcf / Home

Welcome

The StructureMapWcf library is just the code in this blog post put into a library so that you don't have to write it yourself.

To use the StructureMapWcf library, import it into your WCF hosting library as a reference via the Nuget Package Manager. You can do it via the GUI or the command line - here's the command line:

PM> Install-Package StructureMapWcf
Next update your .svc files to use the StructureMapServiceHostFactory:

<%@ ServiceHost Language="C#" Debug="true" Service="CalculatorServiceInterfaces.IPrimeTester"
 Factory="StructureMapWcf.StructureMapServiceHostFactory" %>

Replace the contents of the 'Service' attribute above with the interface or class that will be requested from the StructureMap object factory.

Finally, register your service classes in Structure Map.

using CalculatorServiceImplementation;
using CalculatorServiceImplementation.PolynomialMultipliers;
using CalculatorServiceImplementation.Interfaces;
using CalculatorServiceInterfaces;
using StructureMap.Configuration.DSL;

namespace CalculatorServiceHosting.StructureMapConfig
{
    public class CalculatorRegistry : Registry
    {
        public CalculatorRegistry()
        {
            For<IHcfService>().Use<HcfService>();
            For<IPrimeTester>().Use<PrimeTester>();
            For<IPerfectPowerDetector>().Use<PerfectPowerDetector>();
            For<IPolynomialMultiplierFactory>().Use<PolynomialMultiplierFactory>();

        }
    }
}

Updated