I don’t know if this is too specific a question, if that is possible, but I’m having to port an app that uses Castle Windsor to Unity so that there isn’t a reliance on non-microsoft approved libraries. I know I know but what are you going to do.
Anyway I’ve managed it but I’m not happy with what I’ve got. In Windsor I had this:
Register( AllTypes.Of(typeof(AbstractPresenter<>)).FromAssemblyNamed('Links.Mvp'), AllTypes.Of(typeof(IView)).FromAssemblyNamed('Links.WinForms').WithService.FromInterface());
which I’ve converted to this in unity
RegisterType<IMainView, MainView>(); RegisterType<IConfigureLinkView, ConfigureLinkView>(); RegisterType<IConfigureSourceView, ConfigureSourceView>(); RegisterType<IConfigureSinkView, ConfigureSinkView>(); RegisterType<MainPresenter, MainPresenter>(); RegisterType<ConfigureLinkPresenter, ConfigureLinkPresenter>(); RegisterType<ConfigureSourcePresenter, ConfigureSourcePresenter>(); RegisterType<ConfigureSinkPresenter, ConfigureSinkPresenter>();
As you can see I’m having to register every single thing rather than be able to use some sort of auto-configuration. So my question is: is there a better way of doing this in unity?
Thanks,
Adam.
Cool. This feature is not in unity yet but if you felt a bit ambitious you could setup your own convention based registration. Found below is a snipped that works for the executing assembly and interfaces. Good luck.
P.S. This feels like a big hack, I would probably continue just registering all types by hand.