My "view" code-behind typically looks something like this, with the view-model being injected into its constructor:-
public partial class CustomerView : UserControl
{
public CustomerView(CustomerViewModel viewModel)
{
InitializeComponent();
DataContext = viewModel;
}
}
A view-model looks something like this, with any dependencies being injected into its constructor:-
public class CustomerViewModel
{
...
public CustomerViewModel(SomeDependency someDependency)
{
// etc...
In this example all three classes (the view, view-model, and SomeDependency) reside in the same assembly, and ideally should all be internal as I don't want someone grabbing the assembly and start instantiating things. The trouble is, I can't make the view internal
as it's a partial class. And if I leave it public, it won't compile as you can't pass an internal type to the constructor of a public class.
To get around this, I tried making the constructors internal instead. This compiled, but Castle Windsor throws a runtime exception as it's not possible to register types with internal constructors! So I seem to keep hitting these dead ends - is there any solution, is my class design wrong, or am I worrying unnecessarily about making everything internal?