Ejemplo n.º 1
0
        /// <summary>
        /// 使用Autofac作过滤器依赖解析
        /// 使过滤器支持属性依赖注入功能
        /// </summary>
        /// <param name="fastWebSocketServer">服务器</param>
        public static void SetAutofacFilterAttributeProvider(this IFastWebSocketServer fastWebSocketServer)
        {
            var dependencyResolver = fastWebSocketServer.DependencyResolver as DependencyResolver;

            if (dependencyResolver == null)
            {
                throw new Exception("Autofac不是服务的DependencyResolver,请先调用SetAutofacDependencyResolver");
            }
            fastWebSocketServer.FilterAttributeProvider = new FastWebSocketFilterAttributeProvider(dependencyResolver);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 使用Autofac作依赖解析
        /// 并为相关类型进行注册
        /// </summary>
        /// <param name="fastWebSocketServer">服务器</param>
        public static void SetAutofacDependencyResolver(this IFastWebSocketServer fastWebSocketServer, Action <ContainerBuilder> builderAction)
        {
            var builder = new ContainerBuilder();

            if (builderAction != null)
            {
                builderAction.Invoke(builder);
            }
            var container = builder.Build();

            fastWebSocketServer.DependencyResolver = new AutofacDependencyResolver(container);
        }