Mini 容器学习笔记3——组件的注册(基础篇)

Mini容器主要实现了两个接口,一个是服务注册表接口,一个是服务定位器接口。那么组件的注册就要依靠服务注册表接口IServiceRegistry了。

IServiceRegistry接口的定义:

    public interface IServiceRegistry
    {
       
         IServiceRegistry Register(IComponentInfo info);//通过组件元数据注册组件到容器中
         IServiceRegistry RegisterInstance(string id, object instance);//注册实例
         IServiceRegistry RegisterInstance(string id, Type contract, object instance);//注册实例
         bool HasRegister(Type contract);//是否注册了实现给定契约接口的组件
         bool HasRegister(string id);//是否注册了含有组件Id的组件
         void UnRegister(string id);//通过组件Id注销组件
         void UnRegister(Type contract);//通过契约类型注销相应的组件
         IServiceRegistry Compose(object componentInstance);//将组件实例所依赖的其它组件都通过容器自动注入进来
    }

   IServiceRegistry的扩展方法:

static IServiceRegistry RegisterInstance<TContract, TComponent>(this IServiceRegistry registry, string id, TComponent instance) where TComponent : TContract

static IServiceRegistry RegisterInstance<TContract, TComponent>(this IServiceRegistry registry, TComponent instance) where TComponent : TContract

static IServiceRegistry RegisterInstance(this IServiceRegistry registry, object instance)

static IServiceRegistry Register<TComponent>(this IServiceRegistry registry)

static IServiceRegistry Register<TComponent>(this IServiceRegistry registry, string id)

static IServiceRegistry Register(this IServiceRegistry registry, Type contract, Type component)

static IServiceRegistry Register<TContract, TComponent>(this IServiceRegistry registry, string id, LifestyleFlags lifestyle) where TComponent : TContract

static IServiceRegistry Register<TContract, TComponent>(this IServiceRegistry registry) where TComponent : TContract

static IServiceRegistry Register<TContract, TComponent>(this IServiceRegistry registry, string id) where TComponent : TContract

static IServiceRegistry Register(this IServiceRegistry registry, Type component)

static IServiceRegistry Register(this IServiceRegistry registry, string id, Type component)

static IServiceRegistry Register(this IServiceRegistry registry, string id, Type contract, Type component)

static IServiceRegistry Register<TContract>(this IServiceRegistry registry, Func<object> creator)

static IServiceRegistry Register<TContract>(this IServiceRegistry registry, string id, Func<object> creator)

static IServiceRegistry RegisteryFromAssemblyOf<T>(this IServiceRegistry registry)

     Mini容器通过核心接口保证了一个轻量级内核,通过扩展方法等来丰富Mini容器的Api。
 
   服务注册表门面类ServiceRegistry:向用户提供注册表接口
public static class ServiceRegistry
{
    public static IServiceRegistry Current{ get; }
    public static IServiceRegistry Register<TComponent>()
    public static IServiceRegistry Register<TComponent>(string id)
    public static IServiceRegistry RegisteryFromAssemblyOf<T>()
    public static IServiceRegistry Register(params Action<IBindingExpression>[] handlers)//流畅API注册方式
    public static IServiceRegistry Register(params Action<IComponentExpression>[] handlers))//流畅API注册方式 
    public static bool HasRegister<TContract>()
    public static bool HasRegister(Type service)
    public static bool HasRegister(string id)
    public static IServiceRegistry Compose(object component)
}

Mini 容器官方网站:

       http://nlite.codeplex.com/

推荐资源:

Mini容器介绍

Mini容器学习目录

Mini容器学习目录1——环境搭建(基础篇)

Mini 容器学习笔记2——组件元数据(基础篇)

Mini 容器学习笔记3——组件的注册(基础篇)

Mini 容器学习笔记4——组件的生命周期(应用篇)

Mini 容器学习笔记5——组件的获取

Mini 容器学习笔记6——组件的获取(应用)

Mini 容器学习笔记7——构造函数注入

Mini 容器学习笔记8——字段注入

Mini 容器学习笔记9——属性注入

Mini 容器学习笔记10——方法注入

Mini 容器学习笔记11——Lazy注入

Mini 容器学习笔记12——组合实例

Mini 容器学习笔记13——插件注入

Mini 容器学习笔记14——异常处理

Mini 容器学习笔记15——监听器-初始化监听器

Mini 容器学习笔记16——监听器-释放监听器

Mini 容器学习笔记17——监听器-启动/停止监听器

Mini 容器学习笔记18——监听器-AOP监听器

posted @ 2010-07-06 13:01  风云  阅读(973)  评论(0编辑  收藏  举报