Ejemplo n.º 1
0
        public void Initialize(ExtensionConfigContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _logger = _loggerFactory.CreateLogger(LogCategories.CreateTriggerCategory("Dapr"));
            _logger.LogInformation($"Registered dapr extension");

            context.AddConverter <JObject, SaveStateOptions>(SaveStateOptions);
            context.AddConverter <string, SaveStateOptions>(SaveStateOptions);
            context.AddConverter <byte[], SaveStateOptions>(SaveStateOptions);
            context.AddConverter <JObject, InvokeMethodOptions>(InvokeMethodOptions);

            var daprStateConverter = new DaprStateConverter(_daprService);

            var stateRule = context.AddBindingRule <DaprStateAttribute>();

            stateRule.BindToInput <byte[]>(daprStateConverter);
            stateRule.BindToInput <string>(daprStateConverter);
            stateRule.BindToInput <Stream>(daprStateConverter);
            stateRule.BindToInput <JToken>(daprStateConverter);
            stateRule.BindToInput <JObject>(daprStateConverter);
            stateRule.BindToCollector <SaveStateOptions>((attr) => {
                return(new DaprSaveStateAsyncCollector(attr, _daprService));
            });

            var invokeRule = context.AddBindingRule <DaprInvokeAttribute>();

            invokeRule.BindToCollector <InvokeMethodOptions>((attr) => {
                return(new DaprInvokeMethodAsyncCollector(attr, _daprService));
            });
        }
Ejemplo n.º 2
0
        public void Initialize(ExtensionConfigContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.logger.LogInformation($"Registered dapr extension");

            var daprStateConverter = new DaprStateConverter(this.daprClient);

            // NOTE: The order of conversions for each binding rules is important!
            var stateRule = context.AddBindingRule <DaprStateAttribute>();

            stateRule.AddConverter <JObject, DaprStateRecord>(CreateSaveStateParameters);
            stateRule.AddConverter <object, DaprStateRecord>(CreateSaveStateParameters);
            stateRule.BindToCollector(attr => new DaprSaveStateAsyncCollector(attr, this.daprClient));
            stateRule.BindToInput <string>(daprStateConverter);
            stateRule.BindToInput <JToken>(daprStateConverter);
            stateRule.BindToInput <JObject>(daprStateConverter);
            stateRule.BindToInput <Stream>(daprStateConverter);
            stateRule.BindToInput <byte[]>(daprStateConverter);

            // TODO: This does not work for nulls and value types. Need a better way of doing this conversion.
            stateRule.BindToInput <object?>(daprStateConverter);

            var invokeRule = context.AddBindingRule <DaprInvokeAttribute>();

            invokeRule.AddConverter <JObject, InvokeMethodParameters>(CreateInvokeMethodParameters);
            invokeRule.BindToCollector(attr => new DaprInvokeMethodAsyncCollector(attr, this.daprClient));

            var publishRule = context.AddBindingRule <DaprPublishAttribute>();

            publishRule.AddConverter <JObject, DaprPubSubEvent>(CreatePubSubEvent);
            publishRule.AddConverter <object, DaprPubSubEvent>(CreatePubSubEvent);
            publishRule.BindToCollector(attr => new DaprPublishAsyncCollector(attr, this.daprClient));

            var daprSecretConverter = new DaprSecretConverter(this.daprClient);
            var secretsRule         = context.AddBindingRule <DaprSecretAttribute>();

            secretsRule.BindToInput <JObject>(daprSecretConverter);
            secretsRule.BindToInput <string?>(daprSecretConverter);
            secretsRule.BindToInput <byte[]>(daprSecretConverter);

            context.AddBindingRule <DaprMethodTriggerAttribute>()
            .BindToTrigger(new DaprMethodTriggerBindingProvider(this.daprListener));

            context.AddBindingRule <DaprTopicTriggerAttribute>()
            .BindToTrigger(new DaprTopicTriggerBindingProvider(this.daprListener));
        }