Attachments
abstract class Attachment<T> : IAttachment | |
{ | |
protected T viewModel; | |
protected abstract void OnAttach(); | |
void IAttachment.AttachTo(object obj) | |
{ | |
viewModel = (T)obj; | |
OnAttach(); | |
} | |
} |
class AutoAttachmentModule : Module | |
{ | |
protected override void AttachToComponentRegistration( | |
IComponentRegistry componentRegistry, IComponentRegistration registration) | |
{ | |
registration.Activating += Activating; | |
} | |
void Activating(object sender, ActivatingEventArgs<object> e) | |
{ | |
var vmType = e.Instance.GetType(); | |
var attachments = Conventions.FindAll<AttachmentConventions>(vmType) | |
.Where(t => e.Context.IsRegistered(t)) | |
.Select(t => (IAttachment)e.Context.Resolve(t)); | |
foreach (var a in attachments) | |
a.AttachTo(e.Instance); | |
} | |
} |
interface IAttachment | |
{ | |
void AttachTo(object obj); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment