Edit

Share via


ISite Interface

Definition

Provides functionality required by sites.

public interface ISite : IServiceProvider
[System.Runtime.InteropServices.ComVisible(true)]
public interface ISite : IServiceProvider
Derived
Attributes
Implements

Examples

The following example demonstrates the implementation of ISite, IComponent, and IContainer for use in a library container.

/// <summary>
/// The following example demonstrates the implementation of
/// ISite, IComponent, and IContainer for use in a simple library container.
///
/// This example uses the System, System.ComponentModel, and System.Collections
/// namespaces.
/// </summary>
//This code segment implements the ISite and IComponent interfaces.
//The implementation of the IContainer interface can be seen in the documentation
//of IContainer.

//Implement the ISite interface.

// The ISBNSite class represents the ISBN name of the book component
class ISBNSite : ISite
{
    readonly IComponent m_curComponent;
    readonly IContainer m_curContainer;
    readonly bool m_bDesignMode;
    string m_ISBNCmpName;

    public ISBNSite(IContainer actvCntr, IComponent prntCmpnt)
    {
        m_curComponent = prntCmpnt;
        m_curContainer = actvCntr;
        m_bDesignMode = false;
        m_ISBNCmpName = null;
    }

    //Support the ISite interface.
    public virtual IComponent Component => m_curComponent;

    public virtual IContainer Container => m_curContainer;

    public virtual bool DesignMode => m_bDesignMode;

    public virtual string Name
    {
        get => m_ISBNCmpName;

        set => m_ISBNCmpName = value;
    }

    //Support the IServiceProvider interface.
    public virtual object GetService(Type serviceType) =>
        //This example does not use any service object.
        null;
}

// The BookComponent class represents the book component of the library container.

// This class implements the IComponent interface.

class BookComponent : IComponent
{
    public event EventHandler Disposed;
    ISite m_curISBNSite;

    public BookComponent(string Title, string Author)
    {
        m_curISBNSite = null;
        Disposed = null;
        this.Title = Title;
        this.Author = Author;
    }

    public string Title { get; }

    public string Author { get; }

    public virtual void Dispose() =>
        //There is nothing to clean.
        Disposed?.Invoke(this, EventArgs.Empty);

    public virtual ISite Site
    {
        get => m_curISBNSite;
        set => m_curISBNSite = value;
    }

    public override bool Equals(object cmp)
    {
        BookComponent cmpObj = (BookComponent)cmp;
        return Title.Equals(cmpObj.Title) && Author.Equals(cmpObj.Author);
    }

    public override int GetHashCode() => base.GetHashCode();
}

Remarks

Sites bind a Component to a Container and enable communication between them, as well as provide a way for the container to manage its components.

Sites can also serve as a repository for container-specific, per-component information, such as the component name.

Notes to Implementers

To be a site, a class must implement the ISite interface.

Properties

Component

Gets the component associated with the ISite when implemented by a class.

Container

Gets the IContainer associated with the ISite when implemented by a class.

DesignMode

Determines whether the component is in design mode when implemented by a class.

Name

Gets or sets the name of the component associated with the ISite when implemented by a class.

Methods

GetService(Type)

Gets the service object of the specified type.

(Inherited from IServiceProvider)

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also