Open JenTechSystems opened 8 years ago
What about:
public void ScanTypes(TypeSet types, Registry registry)
{
foreach(var type in types.FindTypes(TypeClassification.Concretes).Where(type => type.CanBeCastTo<Controller>()))
{
registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
};
}
Finding only concrete types first would avoid an unnecessary attempt to cast things that are obviously not controllers.
+1 for a PR
If there is an agreed upon update for this that won't break existing users, feel free to submit a PR and it will be incorporated.
After thinking about this more, might be better off with a Structuremap4.MVC5 fork.
I still need to play around with SM4 more.
I think this also requires a small change to the DefaultRegistry class. It looks like SM4 removed TheCallingAssembly. I rotated in:
using StructureMap;
public class DefaultRegistry : Registry {
#region Constructors and Destructors
public DefaultRegistry() {
Scan(
scan => {
//think this reasonably replaces TheCallingAssembly
scan.Assembly(GetType().Assembly);
scan.WithDefaultConventions();
scan.With(new ControllerConvention());
});
//For<IExample>().Use<Example>();
}
#endregion
}
@dotnetchris I'm still seeing TheCallingAssembly as part of the StructureMap.Graph.IAssemblyScanner. I have version 4.1.2.386 that I'm referencing from NuGet.
Is this project dead ? im planing to upgrade structuredmap from 3 to 4.
With the release of StructureMap4 it appears that the ControllerConvention registration class requires a minor update.
This is how I have changed it, not sure if this is the best way to go: