structuremapopenrasta

OpenRasta DI issues using StructureMap


I'm trying to use StructureMap with OpenRasta. My Configuration class implements IDependencyResolverAccessor. Here's my code to configure the container:

container.Configure(x =>
     {
         x.For<IFileResourceRepository>().Use(
             r => new FileResourceSqlRepository(ConnectionString));
         x.For<ILog>().Use(l => new FileLog(LogFileName, _logLevel));
         x.For<ILogger>().Use<ProTeckLogger>();
         x.For<ILogger<CodecLogSource>>().Use<ProTeckLogger<CodecLogSource>>();
         x.For<ILogger<IOLogSource>>().Use<ProTeckLogger<IOLogSource>>();
         x.For<ILogger<OperationModelLogSource>>().Use<ProTeckLogger<OperationModelLogSource>>();
         x.For<ILogger<PipelineLogSource>>().Use<ProTeckLogger<PipelineLogSource>>();
         x.SetAllProperties(
             policy =>
             policy.Matching(
                 prop => (prop.PropertyType.IsAssignableFrom(typeof (ILogger)))));
         x.SetAllProperties(policy => policy.OfType<IFileResourceRepository>());
         x.SetAllProperties(policy => policy.OfType<ILog>());
         x.SetAllProperties(policy => policy.OfType<ILogger<CodecLogSource>>());
         x.SetAllProperties(policy => policy.OfType<ILogger<IOLogSource>>());
         x.SetAllProperties(policy => policy.OfType<ILogger<OperationModelLogSource>>());
         x.SetAllProperties(policy => policy.OfType<ILogger<PipelineLogSource>>());
     });

I'm getting the following error:

StructureMap Exception Code:  202
No Default Instance defined for PluginFamily System.Diagnostics.TraceSource, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

I suppose perhaps I'm missing a registration? Might I be doing anything else wrong?

Thanks-


Solution

  • It appears that I was, in fact, missing a registration. Adding this line to the container configuration appears to have resolved the issue:

     x.For<TraceSource>().Use(new TraceSource("OpenRasta"));
    

    I don't totally understand how OR uses TraceSource, but for now, I'll take working!