I have several controller classes which use their own configuration classes that set controller classes behavior.
I have controller resolver that picks up desired controller by its name.
Now I want another resolver to bind controller class with its respective configuration class.
What I have now is configuration class nested in partial class of the same name as controller class so the resolver can determine the configuration class unambiguously, but I'm not very happy with this kind of monstrous solotion because the partial class containing only the nested configuration class has to have the same namespace as the controller class which bothers me the most because of its name inconsistency with the folder this class is physically located in as controller classes are in "Controller" folder and their namespaces are "Something.Controller" and configuration classes are in folder "Configuration" but their namespaces also have to be "Something.Controller".
//Path: .\Controller
namespace Something.Controller
{
public partial class MyController : IController
{
}
}
//Path: .\Configuration
namespace Something.Controller
{
public partial class MyController
{
public class MyControllerConfiguration : IConfiguration
{
}
}
}
And the resolvers (no type validation as it's done earlier and the only types that can be passed to these methods already implement IController
):
public class Resolver
{
public IController GetController(Type controllerType)
{
return (IController)Activator.CreateInstance(controllerType);
}
public IConfiguration GetControllerConfiguration(Type controllerType)
{
var configurationType = controllerType.GetNestedTypes().FirstOrDefault(t => typeof(IConfiguration).IsAssignableFrom(t));
if (configurationType != null)
return (IConfiguration)Activator.CreateInstance(configurationType);
else
return null;
}
}
So how can I couple controller class with its configuration class in some more clear way than nesting configuration class in its respective controller class?
EDIT:
Below some usage example:
Let's imagine I have two controllers. Each one has it's own configuration. Now I want to let the user choose which controller to use and then display to the user set of properties from the respective configuration class. Of course I could create the controller instance which would expose its configuration at the time when user sets up the application config but I don't believe it's a good idea.