Quantcast
Channel: Managed Extensibility Framework
Viewing all articles
Browse latest Browse all 265

New Post: Composing inter-dependant objects

$
0
0
For any of those that are interested, I ended up creating an interface IRequireSession which has the following declaration
    public interface IRequireSession
    {
        ISession Session { get; set; }
    }
And is implemented in a Form base class :
    public class DataForm : Form, IRequireSession
    {
        private ISession _session;

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Import()]
        public ISession Session
        {
            get { return _session; }
            set { 
                _session = value;
                SetSession(this.Controls);
            }
        }

        private void SetSession(Control.ControlCollection controls)
        {
            foreach (Control control in controls)
            {
                if (control is IRequireSession)
                    ((IRequireSession)control).Session = _session;
                SetSession(control.Controls);
            }
        }
    }
This means that I can derive my normal forms from DataForm and get the session passed through to any user controls that implement IRequireSession. Although, I've got a funny feeling that MEF doesn't support attributes on base classes. . I guess I'll find out soon enough.

Viewing all articles
Browse latest Browse all 265

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>