While I was confused by other posts mentioning LookForRegistries() by scan assembly, Derik Whittaker’s post explained how to do auto-wire in SC2.5, that’s just what I want! But I couldn’t move this code into a Registry class. Meanwhile I saw Jeremy Miller kept saying:
Don’t ever make any calls to ObjectFactory within a Registry.
I’m not sure does this mean I am not supposed to do OBjectFactory.Configure() in my Registry. If no, how can I refactor this code?
private static void SetupStructureMap()
{
ObjectFactory.Initialize(
x=>
{
// <a href="http://codebetter.com/blogs/jeremy.miller/archive/2008/10/25/initializing-and-configuring-a-structuremap-container.aspx">Ingore config file</a>
x.UseDefaultStructureMapConfigFile = false
x.AddRegistry<AuthorizationRegistry>();
x.AddRegistry<RepositoriesRegistry>();
x.Scan(scanner =>
{
scanner.Assembly("Aglc.Stakeholder.Data.LINQ");
scanner.WithDefaultConventions();
});
});
}
Frank,
I think what you have there is fine, you are not calling ObjectFactory from within the registry, you are dynamically creating the registry inside the initialize method. That is essentially what I am doing, except I have a seperate registry in each assembly and do this:
ObjectFactory.Initialize(x =>{
x.AddRegistry(new InfrastructureRegistry());
x.AddRegistry(new CoreRegistry());
});
I’m actually thinking to adopt the idea of ‘having a separate registry in each assembly’ recently. So the hooking-up code in UI will be similar to the code I saw yesterday during the virtual conference:
x.Scan(scanner =>
{
scanner.AssemblyContainingType();
scanner.WithDefaultConventions();
});
I like this better because there is no string literal to describe the assembly name.