示例#1
0
        public void AddServices(IServiceCollection services)
        {
            var option = new CapBusOptions();

            configure(option);
            services.AddSingleton <CapBusOptions>(x => option);
            services.AddSingleton <IEasyCachingBus, DefaultCAPBus>();
            services.AddSingleton <IConsumerServiceSelector, EasyCachingConsumerServiceSelector>();
        }
示例#2
0
        public void AddServices(IServiceCollection services)
        {
            var option = new CapBusOptions();

            configure(option);
            services.AddSingleton <CapBusOptions>(x => option);
            services.AddSingleton <IEasyCachingBus, DefaultCAPBus>();
            services.AddSingleton(DynamicCreateSubscribeClass.GetCacheSubscribeType(option));
        }
示例#3
0
        /// <summary>
        /// 获取缓存订阅者的Type
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public static Type GetCacheSubscribeType(CapBusOptions options)
        {
            var type = typeof(CacheSubscribe);

            var moduleName   = type.GetTypeInfo().Module.Name;
            var assemblyName = new AssemblyName(Guid.NewGuid().ToString());

            var module = AssemblyBuilder
                         .DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run)
                         .DefineDynamicModule(moduleName);



            var builder = module.DefineType("CacheSubscribe", TypeAttributes.Class, typeof(CacheSubscribe));

            var met = type.GetMethods();

            MethodBuilder methodBuilder = builder.DefineMethod("ReceiveMessage", MethodAttributes.Public, null, new Type[] { typeof(EasyCachingMessage) });


            Type[] ctorParams = new Type[] { typeof(string), typeof(string) };

            //获取构造器信息
            ConstructorInfo classCtorInfo = typeof(EasyCachingSubscribeAttribute).GetConstructor(ctorParams);

            //动态创建CapSubscribeAttribute
            CustomAttributeBuilder myCABuilder = new CustomAttributeBuilder(
                classCtorInfo,
                new object[] { options.TopicName, options.QueuePrefixName + GetQueueSuffixName() });

            //将上面动态创建的Attribute附加到(动态创建的)类型MyType
            methodBuilder.SetCustomAttribute(myCABuilder);

            //生成指令
            ILGenerator numberGetIL = methodBuilder.GetILGenerator();

            numberGetIL.Emit(OpCodes.Ldarg_0);
            numberGetIL.Emit(OpCodes.Ldarg_1);
            numberGetIL.Emit(OpCodes.Call, type.GetMethod("ReceiveMessage", new Type[] { typeof(EasyCachingMessage) }));

            numberGetIL.Emit(OpCodes.Ret);

            return(builder.CreateTypeInfo().AsType());
        }
示例#4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="capBus"></param>
 /// <param name="optionsAccs"></param>
 public DefaultCAPBus(ICapPublisher capBus, CapBusOptions optionsAccs)
 {
     _capBus  = capBus;
     _options = optionsAccs;
 }