Я пытаюсь зарегистрировать компонент в IWindsorContainer, т.е.
_container.Register(Component.For<IView>().ImplementedBy<View>());
_container.Register(Component.For<Presenter>());
Когда я разрешаю представление, я также хочу создать Presenter, чтобы я мог подписаться на любые события, генерируемые представлением. Можно ли это сделать во время процесса регистрации или мне нужно какое-то средство?
public interface IView
{
event Action<string> Process;
}
public class View : IView
{
public event Action<string> Process;
}
public class Presenter
{
public Presenter(IView view)
{
view.Process += (args) => this.DoSomeStuff();
}
}
Я написал пользовательскую регистрацию, но она не работает должным образом
public class ViewRegistration<TView> : IRegistration where TView : IView
{
private Type _implementation, _presenter;
public ViewRegistration<TView> ImplementedBy<TImplementation>() where TImplementation : TView
{
_implementation = typeof(TImplementation);
return this;
}
public ViewRegistration<TView> Using<TPresenter>()
{
_presenter = typeof(TPresenter);
return this;
}
public void Register(IKernel kernel)
{
var model = kernel.ComponentModelBuilder.BuildModel(_implementation.FullName, typeof(TView), _implementation, null);
if (_presenter != null)
{
var test = kernel.ComponentModelBuilder.BuildModel(_presenter.FullName, _presenter, _presenter, null);
model.AddDependent(test);
}
kernel.AddCustomComponent(model);
}
}