How can I add some scoping when I scan my assemblies ? Google doesn't seem quite happy with "structuremap scan cacheby" :/
ObjectFactory.Configure(registry =>
{
registry.Scan(x =>
{
x.AssemblyContainingType(typeof(IRepository<>));
x.With<DefaultConventionScanner>();
});
}
Here's a way to make it work with the newer IRegistrationConvention API:
public class SingletonConvention : IRegistrationConvention
{
#region IRegistrationConvention Members
public void Process(Type type, Registry registry)
{
registry.For(type).Singleton();
}
#endregion
}
It can be used like this:
container.Configure(registry =>
{
registry.Scan(x =>
{
x.AssemblyContainingType<Foo>();
x.AddAllTypesOf<IFoo>();
x.Convention<SingletonConvention>();
});
});
The way I got around this was to build a custom convention scanner:
public class CustomScanner : ITypeScanner
{
#region ITypeScanner Members
public void Process(Type type, PluginGraph graph)
{
graph.AddType(type);
var family = graph.FindFamily(type);
family.AddType(type);
family.SetScopeTo(InstanceScope.Hybrid);
}
#endregion
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With