public void Initialize(ExtensionConfigContext context) { using (var scope = _provider.CreateScope()) { var services = scope.ServiceProvider; var dependency = services.GetService <DependencyGraphBravo>(); Log.LogTrace("Doing 1st work with scoped dependency bravo: {0} a: {1} b: {2}", dependency.GetHashCode(), dependency.A.GetHashCode(), dependency.B.GetHashCode()); } using (var scope = _provider.CreateScope()) { var services = scope.ServiceProvider; var dependency = services.GetService <DependencyGraphBravo>(); Log.LogTrace("Doing 2nd work with scoped dependency bravo: {0} a: {1} b: {2}", dependency.GetHashCode(), dependency.A.GetHashCode(), dependency.B.GetHashCode()); } }
public void Initialize(ExtensionConfigContext context) { EnsureArg.IsNotNull(context); foreach (var startable in _provider.GetServices <IStartable>()) { startable.Start(); } var initTasks = _provider.GetServices <IRequireInitializationOnFirstRequest>() .Select(x => x.EnsureInitialized()) .ToArray(); Task.WhenAll(initTasks) .ConfigureAwait(false) .GetAwaiter() .OnCompleted(() => Trace.WriteLine("Functions initialization complete.")); }
/// <summary> /// This callback is invoked by the WebJobs framework before the host starts execution. /// It should add the binding rules and converters for our new <see cref="SampleAttribute"/> /// </summary> /// <param name="context"></param> public void Initialize(ExtensionConfigContext context) { // Register converters. These help convert between the user's parameter type // and the type specified by the binding rules. // This allows a user to bind to IAsyncCollector<string>, and the sdk // will convert that to IAsyncCollector<SampleItem> context.AddConverter <string, SampleItem>(ConvertToItem); // This is useful on input. context.AddConverter <SampleItem, string>(ConvertToString); // Create 2 binding rules for the Sample attribute. var rule = context.AddBindingRule <SampleAttribute>(); rule.BindToInput <SampleItem>(BuildItemFromAttr); rule.BindToCollector <SampleItem>(BuildCollector); }
/// <summary> /// Initializes the SQL binding rules /// </summary> /// <param name="context"> The config context </param> /// <exception cref="ArgumentNullException"> /// Thrown if context is null /// </exception> public void Initialize(ExtensionConfigContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var inputOutputRule = context.AddBindingRule <SqlAttribute>(); var converter = new SqlConverter(_configuration); inputOutputRule.BindToInput <SqlCommand>(converter); inputOutputRule.BindToInput <string>(typeof(SqlGenericsConverter <string>), _configuration); inputOutputRule.BindToCollector <OpenType>(typeof(SqlAsyncCollectorBuilder <>), _configuration, _loggerFactory); inputOutputRule.BindToInput <OpenType>(typeof(SqlGenericsConverter <>), _configuration); var triggerRule = context.AddBindingRule <SqlTriggerAttribute>(); triggerRule.BindToTrigger(new SqlTriggerAttributeBindingProvider(_configuration, _loggerFactory)); }
/// <summary> /// Internal initialization call from the WebJobs host. /// </summary> /// <param name="context">Extension context provided by WebJobs.</param> void IExtensionConfigProvider.Initialize(ExtensionConfigContext context) { ConfigureLoaderHooks(); context.ApplyConfig(this, "DurableTask"); // Register the trigger bindings JobHostConfiguration hostConfig = context.Config; ILogger logger = context.Config.LoggerFactory.CreateLogger(LoggerCategoryName); this.traceHelper = new EndToEndTraceHelper(hostConfig, logger); this.httpApiHandler = new HttpApiHandler(this, logger); this.lifeCycleNotificationHelper = new LifeCycleNotificationHelper(this, context); // Register the non-trigger bindings, which have a different model. var bindings = new BindingHelper(this, this.traceHelper); // For 202 support if (this.NotificationUrl == null) { #pragma warning disable CS0618 // Type or member is obsolete this.NotificationUrl = context.GetWebhookHandler(); #pragma warning restore CS0618 // Type or member is obsolete } // Note that the order of the rules is important var rule = context.AddBindingRule <OrchestrationClientAttribute>() .AddConverter <JObject, StartOrchestrationArgs>(bindings.JObjectToStartOrchestrationArgs); rule.BindToCollector <StartOrchestrationArgs>(bindings.CreateAsyncCollector); rule.BindToInput <DurableOrchestrationClient>(this.GetClient); context.AddBindingRule <OrchestrationTriggerAttribute>() .BindToTrigger(new OrchestrationTriggerAttributeBindingProvider(this, context, this.traceHelper)); context.AddBindingRule <ActivityTriggerAttribute>() .BindToTrigger(new ActivityTriggerAttributeBindingProvider(this, context, this.traceHelper)); AzureStorageOrchestrationServiceSettings settings = this.GetOrchestrationServiceSettings(); this.orchestrationService = new AzureStorageOrchestrationService(settings); this.taskHubWorker = new TaskHubWorker(this.orchestrationService, this, this); this.taskHubWorker.AddOrchestrationDispatcherMiddleware(this.OrchestrationMiddleware); }
private void InitilizeBlobBindings(ExtensionConfigContext context) { #pragma warning disable CS0618 // Type or member is obsolete Uri url = context.GetWebhookHandler(); #pragma warning restore CS0618 // Type or member is obsolete _logger.LogInformation($"registered http endpoint = {url?.GetLeftPart(UriPartial.Path)}"); var rule = context.AddBindingRule <BlobAttribute>(); // Bind to multiple blobs (either via a container; an IEnumerable<T>) rule.BindToInput <BlobContainerClient>(this); rule.BindToInput <MultiBlobContext>(this); // Intermediate private context to capture state rule.AddOpenConverter <MultiBlobContext, IEnumerable <BlobCollectionType> >(typeof(BlobCollectionConverter <>), this); // BindToStream will also handle the custom Stream-->T converters. rule.BindToStream(CreateStreamAsync, FileAccess.ReadWrite); // Precedence, must beat CloudBlobStream // Normal blob // These are not converters because Blob/Page/Append affects how we *create* the blob. rule.BindToInput <BlockBlobClient>((attr, cts) => CreateBlobReference <BlockBlobClient>(attr, cts)); rule.BindToInput <PageBlobClient>((attr, cts) => CreateBlobReference <PageBlobClient>(attr, cts)); rule.BindToInput <AppendBlobClient>((attr, cts) => CreateBlobReference <AppendBlobClient>(attr, cts)); rule.BindToInput <BlobClient>((attr, cts) => CreateBlobReference <BlobClient>(attr, cts)); rule.BindToInput <BlobBaseClient>((attr, cts) => CreateBlobReference <BlobBaseClient>(attr, cts)); // If caching is enabled, create a binding for that if (_functionDataCache != null && _functionDataCache.IsEnabled) { rule.When("Access", FileAccess.Read). BindToInput <ICacheAwareReadObject>((attr, ctx) => CreateCacheAwareReadObjectAsync(attr, ctx)); rule.When("Access", FileAccess.Write). BindToInput <ICacheAwareWriteObject>((attr, ctx) => CreateCacheAwareWriteObjectAsync(attr, ctx)); } // CloudBlobStream's derived functionality is only relevant to writing. check derived functionality rule.When("Access", FileAccess.Write). BindToInput <Stream>(ConvertToCloudBlobStreamAsync); RegisterCommonConverters(rule); rule.AddConverter(new StorageBlobConverter <BlobClient>()); }
private void InitializeForFunctionsV1(ExtensionConfigContext context) { #if FUNCTIONS_V1 context.ApplyConfig(this.Options, "DurableTask"); this.nameResolver = context.Config.NameResolver; this.ResolveAppSettingOptions(); ILogger logger = context.Config.LoggerFactory.CreateLogger(LoggerCategoryName); this.TraceHelper = new EndToEndTraceHelper(logger, this.Options.Tracing.TraceReplayEvents); this.connectionStringResolver = new WebJobsConnectionStringProvider(); this.durabilityProviderFactory = new AzureStorageDurabilityProviderFactory(new OptionsWrapper <DurableTaskOptions>(this.Options), this.connectionStringResolver); this.defaultDurabilityProvider = this.durabilityProviderFactory.GetDurabilityProvider(); this.LifeCycleNotificationHelper = this.CreateLifeCycleNotificationHelper(); var messageSerializerSettingsFactory = new MessageSerializerSettingsFactory(); var errorSerializerSettingsFactory = new ErrorSerializerSettingsFactory(); this.MessageDataConverter = new MessagePayloadDataConverter(messageSerializerSettingsFactory.CreateJsonSerializerSettings(), true); this.ErrorDataConverter = new MessagePayloadDataConverter(errorSerializerSettingsFactory.CreateJsonSerializerSettings(), true); this.HttpApiHandler = new HttpApiHandler(this, logger); #endif }
public void Initialize(ExtensionConfigContext context) { var bindingRule = context.AddBindingRule <PerperAttribute>(); bindingRule.BindToValueProvider <OpenType>((a, t) => Task.FromResult <IValueBinder>(new PerperValueBinder(_fabricContext, a, t))); var streamTriggerBindingRule = context.AddBindingRule <PerperStreamTriggerAttribute>(); streamTriggerBindingRule.BindToTrigger(new PerperTriggerBindingProvider <PerperStreamTriggerAttribute>(_fabricContext, _logger)); var workerTriggerBindingRule = context.AddBindingRule <PerperWorkerTriggerAttribute>(); workerTriggerBindingRule.BindToTrigger(new PerperTriggerBindingProvider <PerperWorkerTriggerAttribute>(_fabricContext, _logger)); var moduleTriggerBindingRule = context.AddBindingRule <PerperModuleTriggerAttribute>(); moduleTriggerBindingRule.BindToTrigger(new PerperTriggerBindingProvider <PerperModuleTriggerAttribute>(_fabricContext, _logger)); }
public static void Create(ExtensionConfigContext context) { var loggerFactory = context.Config.LoggerFactory; var traceBinderType = typeof(JobHostConfiguration).Assembly.GetType("Microsoft.Azure.WebJobs.Host.Bindings.TraceWriterBindingProvider"); IBindingProvider inner = (IBindingProvider)Activator.CreateInstance(traceBinderType, loggerFactory); Func <string, FunctionDescriptor> funcLookup = context.Config.GetService <Func <string, FunctionDescriptor> >(); // Func<string, FunctionDescriptor> funcLookup = null; if (funcLookup != null && inner != null) { IBindingProvider wrapper = new Wrapper(inner, funcLookup); var registry = context.Config.GetService <IExtensionRegistry>(); registry.RegisterExtension(typeof(IBindingProvider), wrapper); } }
private static void InitializeServiceLocator(ExtensionConfigContext context) { var bootstrapperCollector = new BootstrapperCollector(); var bootstrappers = bootstrapperCollector.GetBootstrappers(); if (bootstrappers.Count == 0) { throw new BootstrapperNotFoundException("No bootstrapper instances had been recognized."); } var modules = new List <Module>(); foreach (var bootstrapper in bootstrappers) { var instance = (IBootstrapper)Activator.CreateInstance(bootstrapper); modules.AddRange(instance.CreateModules()); } InjectConfiguration.Initialize(modules.ToArray()); }
/// <inheritdoc /> public void Initialize(ExtensionConfigContext context) { if (context == null) { throw new ArgumentNullException("context"); } _trace = context.Trace; INameResolver nameResolver = context.Config.GetService <INameResolver>(); IConverterManager converterManager = context.Config.GetService <IConverterManager>(); // Use this if there is no other connection string set. _defaultConnectionString = nameResolver.Resolve(AzureWebJobsCosmosDBConnectionStringName); BindingFactory factory = new BindingFactory(nameResolver, converterManager); IBindingProvider outputProvider = factory.BindToCollector <CosmosDBAttribute, OpenType>(typeof(CosmosDBCollectorBuilder <>), this); IBindingProvider outputProviderJObject = factory.BindToCollector <CosmosDBAttribute, JObject>(typeof(CosmosDBCollectorBuilder <>), this); IBindingProvider clientProvider = factory.BindToInput <CosmosDBAttribute, DocumentClient>(new CosmosDBClientBuilder(this)); IBindingProvider jArrayProvider = factory.BindToInput <CosmosDBAttribute, JArray>(typeof(CosmosDBJArrayBuilder), this); IBindingProvider enumerableProvider = factory.BindToInput <CosmosDBAttribute, IEnumerable <OpenType> >(typeof(CosmosDBEnumerableBuilder <>), this); enumerableProvider = factory.AddValidator <CosmosDBAttribute>(ValidateInputBinding, enumerableProvider); IBindingProvider inputProvider = factory.BindToGenericValueProvider <CosmosDBAttribute>((attr, t) => BindForItemAsync(attr, t)); inputProvider = factory.AddValidator <CosmosDBAttribute>(ValidateInputBinding, inputProvider); context.AddBindingRule <CosmosDBAttribute>() .AddConverter <JObject, JObject>(s => s); IExtensionRegistry extensions = context.Config.GetService <IExtensionRegistry>(); extensions.RegisterBindingRules <CosmosDBAttribute>(ValidateConnection, nameResolver, outputProvider, outputProviderJObject, clientProvider, jArrayProvider, enumerableProvider, inputProvider); context.Config.RegisterBindingExtensions(new CosmosDBTriggerAttributeBindingProvider(nameResolver, this, LeaseOptions)); }
public void Initialize(ExtensionConfigContext context) { if (context == null) { throw new ArgumentNullException("context"); } var secretRule = context.AddBindingRule <KeyVaultSecretAttribute>(); secretRule.BindToInput(new KeyVaultSecretManager()); var certificateRule = context.AddBindingRule <KeyVaultCertificateAttribute>(); certificateRule.BindToInput(new KeyVaultCertificateManager()); var keyRule = context.AddBindingRule <KeyVaultKeyAttribute>(); keyRule.BindToInput(new KeyVaultKeyManager()); }
void IExtensionConfigProvider.Initialize(ExtensionConfigContext context) { IConverterManager cm = context.Config.GetOrCreateConverterManager(); cm.AddConverter <string, FakeQueueData>(x => new FakeQueueData { Message = x }); cm.AddConverter <FakeQueueData, string>(msg => msg.Message); IExtensionRegistry extensions = context.Config.GetService <IExtensionRegistry>(); var bindingProvider = new FakeQueueBindingProvider(this, cm); extensions.RegisterExtension <IBindingProvider>(bindingProvider); var triggerBindingProvider = new FakeQueueTriggerBindingProvider(this, cm); extensions.RegisterExtension <ITriggerBindingProvider>(triggerBindingProvider); }
public static ExtensionConfigContext AddAllConverters(this ExtensionConfigContext context, Microsoft.Extensions.Logging.ILogger logger) { return(context .AddJsonConverter(logger) .AddByteArrayConverter(logger) .AddEventDataConverter(logger) .AddJObjectConverter(logger) .AddDynamicConverter(logger) .AddExpandoObjectConverter(logger) .AddResolvedEventListConverter(logger) .AddResolvedEventConverter(logger) .AddResolvedEventToStringConverter(logger) .AddResolvedEventListToStringConverter(logger) .AddResolvedEventToByteArrayConverter(logger) .AddResolvedEventListToByteArrayListConverter(logger) .AddOpenConverter <IList <OpenType>, IList <EventStoreData> >(typeof(ToOpenTypeListConverter <>), logger) .AddOpenConverter <OpenType, EventStoreData>(typeof(ToOpenTypeConverter <>), logger) .AddOpenConverter <IList <ResolvedEvent>, IList <OpenType> >(typeof(FromOpenTypeConverter <>), logger)); }
/// <summary> /// Initializes the extension configuration provider. /// </summary> /// <param name="context">The extension configuration context.</param> public void Initialize(ExtensionConfigContext context) { var logger = context.Config.LoggerFactory.CreateLogger(LogCategories.CreateTriggerCategory("Mqtt")); var nameResolver = context.Config.GetService <INameResolver>(); var mqttConnectionFactory = new MqttConnectionFactory(logger, new MqttFactory(), nameResolver); context.Config.AddService(typeof(IMqttConnectionFactory), mqttConnectionFactory); var mqttAttributeBindingRule = context.AddBindingRule <MqttAttribute>(); mqttAttributeBindingRule.BindToCollector((attr) => new MqttMessageCollector(attr, mqttConnectionFactory.GetMqttConnection(attr))); context.Config.RegisterBindingExtension(new MqttTriggerAttributeBindingProvider(nameResolver, mqttConnectionFactory, logger)); // todo: in later release of the Functions SDK (currently beta 25) replace the line above with the two below //var mqttTriggerAttributeBindingRule = context.AddBindingRule<MqttTriggerAttribute>(); //mqttTriggerAttributeBindingRule.BindToTrigger<IMqttMessage>(new MqttTriggerAttributeBindingProvider(nameResolver, _mqttConnectionFactory, logger)); }
public void Initialize(ExtensionConfigContext context) { if (context == null) { throw new ArgumentNullException("context"); } else if (context.Trace == null) { throw new ArgumentNullException("context.Trace"); } _tracer = context.Trace; Uri url = context.GetWebhookHandler(); _tracer.Trace(new TraceEvent(System.Diagnostics.TraceLevel.Info, $"registered EventGrid Endpoint = {url}")); // Register our extension binding providers context.Config.RegisterBindingExtension(new EventGridTriggerAttributeBindingProvider(this)); }
/// <inheritdoc /> public void Initialize(ExtensionConfigContext context) { if (context == null) { throw new ArgumentNullException("context"); } _nameResolver = context.Config.GetService <INameResolver>(); IConverterManager converterManager = context.Config.GetService <IConverterManager>(); // Set defaults, to be used if no other values are found: _defaultApiKey = _nameResolver.Resolve(AzureWebJobsMobileAppApiKeyName); string uriString = _nameResolver.Resolve(AzureWebJobsMobileAppUriName); Uri.TryCreate(uriString, UriKind.Absolute, out _defaultMobileAppUri); var rule = context.AddBindingRule <MobileTableAttribute>(); rule.AddValidator(ValidateMobileAppUri); rule.BindToCollector <OpenType>(typeof(MobileTableCollectorBuilder <>), this); rule.BindToInput <IMobileServiceClient>(new MobileTableClientBuilder(this)); // MobileType matching needs to know whether the attribute defines 'TableName', but // OpenTypes can't get access to the attribute. So use filters to split into 2 cases. rule.WhenIsNotNull(nameof(MobileTableAttribute.TableName)). BindToInput <IMobileServiceTableQuery <MobileTypeWithTableName> >(typeof(MobileTableQueryBuilder <>), this); rule.WhenIsNull(nameof(MobileTableAttribute.TableName)). BindToInput <IMobileServiceTableQuery <MobileTypeWithoutTableName> >(typeof(MobileTableQueryBuilder <>), this); rule.BindToInput <IMobileServiceTable>(new MobileTableJObjectTableBuilder(this)); rule.WhenIsNotNull(nameof(MobileTableAttribute.TableName)). BindToInput <IMobileServiceTable <MobileTypeWithTableName> >(typeof(MobileTablePocoTableBuilder <>), this); rule.WhenIsNull(nameof(MobileTableAttribute.TableName)). BindToInput <IMobileServiceTable <MobileTypeWithoutTableName> >(typeof(MobileTablePocoTableBuilder <>), this); rule.WhenIsNotNull(nameof(MobileTableAttribute.TableName)). BindToValueProvider <MobileTypeWithTableName>(BindForItemAsync).AddValidator(HasId); rule.WhenIsNull(nameof(MobileTableAttribute.TableName)). BindToValueProvider <MobileTypeWithoutTableName>(BindForItemAsync).AddValidator(HasId); }
/// <inheritdoc /> public void Initialize(ExtensionConfigContext context) { if (context == null) { throw new ArgumentNullException("context"); } // Set the default exception handler for background exceptions // coming from MessageReceivers. Options.ExceptionHandler = (e) => { LogExceptionReceivedEvent(e, _loggerFactory); }; // register our trigger binding provider ServiceBusSessionTriggerAttributeBindingProvider triggerBindingProvider = new ServiceBusSessionTriggerAttributeBindingProvider(_nameResolver, _options, _sessionProvider, _configuration); context.AddBindingRule <ServiceBusSessionTriggerAttribute>().BindToTrigger(triggerBindingProvider); }
/// <summary> /// This callback is invoked by the WebJobs framework before the host starts execution. /// It adds the binding rules and converters for the event stream backed orchestration /// classes /// </summary> /// <param name="context"> /// The context to which extensions can be registered /// </param> public void Initialize(ExtensionConfigContext context) { // Add binding rules ... with converters // [Command] var commandRule = context.AddBindingRule <EventStreamBackedCommandOrchestrationTriggerAttribute>() .AddConverter <string, StartCommandOrchestrationArgs>(this.StringToStartCommandArgs) .AddConverter <JObject, StartCommandOrchestrationArgs>(this.JObjectToStartCommandArgs); commandRule.BindToCollector <StartCommandOrchestrationArgs>(this.CreateCommandAsyncCollector); commandRule.BindToInput <EventStreamBackedCommandOrchestrator>(this.GetCommandOrchestration); // [Query] var queryRule = context.AddBindingRule <EventStreamBackedQueryOrchestrationTriggerAttribute>() .AddConverter <string, StartQueryOrchestrationArgs>(this.StringToStartQueryArgs) .AddConverter <JObject, StartQueryOrchestrationArgs>(this.JObjectToStartQueryArgs); queryRule.BindToCollector <StartQueryOrchestrationArgs>(this.CreateQueryAsyncCollector); queryRule.BindToInput <EventStreamBackedQueryOrchestrator>(this.GetQueryOrchestration); // [Idetifier Group] var identifierGroupRule = context.AddBindingRule <EventStreamBackedIdentifierGroupOrchestrationTriggerAttribute>() .AddConverter <string, StartIdentifierGroupOrchestrationArgs>(this.StringToStartIdentifierGroupArgs) .AddConverter <JObject, StartIdentifierGroupOrchestrationArgs>(this.JObjectToStartIdentifierGroupArgs); identifierGroupRule.BindToCollector <StartIdentifierGroupOrchestrationArgs>(this.CreateIdentifierGroupAsyncCollector); identifierGroupRule.BindToInput <EventStreamBackedIdentifierGroupOrchestrator>(this.GetGroupOrchestration); // [Classifier] var classifierRule = context.AddBindingRule <EventStreamBackedClassifierOrchestrationTriggerAttribute>() .AddConverter <string, StartClassifierOrchestrationArgs>(this.StringToStartClassifierArgs) .AddConverter <JObject, StartClassifierOrchestrationArgs>(this.JObjectToStartClassifierArgs); classifierRule.BindToCollector <StartClassifierOrchestrationArgs>(this.CreateClassifierAsyncCollector); classifierRule.BindToInput <EventStreamBackedClassifierOrchestrator>(this.GetClassifierOrchestration); // [Projection] var projectionRule = context.AddBindingRule <EventStreamBackedProjectionOrchestrationTriggerAttribute>() .AddConverter <string, StartProjectionOrchestrationArgs>(this.StringToStartProjectionArgs) .AddConverter <JObject, StartProjectionOrchestrationArgs>(this.JObjectToStartProjectionArgs); projectionRule.BindToCollector <StartProjectionOrchestrationArgs>(this.CreateProjectionAsyncCollector); projectionRule.BindToInput <EventStreamBackedProjectionOrchestrator>(this.GetProjectionOrchestration); }
public void Initialize(ExtensionConfigContext context) { if (context == null) { throw new ArgumentNullException("context"); } var fileBindingProvider = new FileAttributeBindingProvider(_options, _nameResolver); context.AddBindingRule <FileAttribute>() .Bind(fileBindingProvider); var triggerBindingProvider = new FileTriggerAttributeBindingProvider(_options, _loggerFactory, _fileProcessorFactory); var triggerRule = context.AddBindingRule <FileTriggerAttribute>(); triggerRule.BindToTrigger(triggerBindingProvider); triggerRule.AddConverter <string, FileSystemEventArgs>(p => FileTriggerBinding.GetFileArgsFromString(p)); triggerRule.AddConverter <FileSystemEventArgs, Stream>(p => File.OpenRead(p.FullPath)); }
public void Initialize(ExtensionConfigContext context) { configuration.ConfigurationSection.Bind(options); context .AddConverter <KafkaEventData, string>(ConvertKafkaEventData2String) .AddConverter <KafkaEventData, ISpecificRecord>(ConvertKafkaEventData2AvroSpecific) .AddConverter <KafkaEventData, byte[]>(ConvertKafkaEventData2Bytes); // register our trigger binding provider var triggerBindingProvider = new KafkaTriggerAttributeBindingProvider(config, options, converterManager, nameResolver, loggerFactory); context.AddBindingRule <KafkaTriggerAttribute>() .BindToTrigger(triggerBindingProvider); // register output binding context.AddBindingRule <KafkaAttribute>() .BindToCollector(BuildCollectorFromAttribute); }
public void Initialize(ExtensionConfigContext context) { var services = new ContainerBuilder(); RegisterServices(services); var container = services.Build(); //var serviceProvider = services.BuildServiceProvider(true); context .AddBindingRule <InjectAttribute>() .Bind(new InjectBindingProvider(container)); var registry = context.Config.GetService <IExtensionRegistry>(); var filter = new ScopeCleanupFilter(); registry.RegisterExtension(typeof(IFunctionInvocationFilter), filter); registry.RegisterExtension(typeof(IFunctionExceptionFilter), filter); }
public void Initialize(ExtensionConfigContext context) { // Register converters. These help convert between the user's parameter type // and the type specified by the binding rules. // This allows a user to bind to IAsyncCollector<string>, and the sdk // will convert that to IAsyncCollector<SampleItem> context.AddConverter <string, FileContent>(ConvertToItem); // This is useful on input binding. context.AddConverter <FileContent, string>(ConvertToString); // Create 2 binding rules for the Sample attribute. var rule = context.AddBindingRule <FileAccessAttribute>(); //On input binding to read from the file rule.BindToInput <FileContent>(BuildItemFromAttr); //on output binding to make call to AddAsync method in IAyncCollector<FileContent> rule.BindToCollector <FileContent>(BuildCollector); }
public void Initialize(ExtensionConfigContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (string.IsNullOrEmpty(options.ConnectionString)) { options.ConnectionString = nameResolver.Resolve(Constants.AzureSignalRConnectionStringName); } var serviceTransportTypeStr = nameResolver.Resolve(Constants.ServiceTransportTypeName); if (Enum.TryParse <ServiceTransportType>(serviceTransportTypeStr, out var transport)) { options.AzureSignalRServiceTransportType = transport; } else { logger.LogWarning($"Unsupported service transport type: {serviceTransportTypeStr}. Use default {options.AzureSignalRServiceTransportType} instead."); } StaticServiceHubContextStore.ServiceManagerStore = new ServiceManagerStore(options.AzureSignalRServiceTransportType, Configuration, loggerFactory); context.AddConverter <string, JObject>(JObject.FromObject) .AddConverter <SignalRConnectionInfo, JObject>(JObject.FromObject) .AddConverter <JObject, SignalRMessage>(input => input.ToObject <SignalRMessage>()) .AddConverter <JObject, SignalRGroupAction>(input => input.ToObject <SignalRGroupAction>()); var signalRConnectionInfoAttributeRule = context.AddBindingRule <SignalRConnectionInfoAttribute>(); signalRConnectionInfoAttributeRule.AddValidator(ValidateSignalRConnectionInfoAttributeBinding); signalRConnectionInfoAttributeRule.BindToInput <SignalRConnectionInfo>(GetClientConnectionInfo); var signalRAttributeRule = context.AddBindingRule <SignalRAttribute>(); signalRAttributeRule.AddValidator(ValidateSignalRAttributeBinding); signalRAttributeRule.BindToCollector <SignalROpenType>(typeof(SignalRCollectorBuilder <>), this); logger.LogInformation("SignalRService binding initialized"); }
/// <summary> /// Initializes the specified context. /// </summary> /// <param name="context">The context.</param> public void Initialize(ExtensionConfigContext context) { // Tell the Functions host that we want to add a new binding based on the KeyVaultSecret attribute class context.AddBindingRule <KeyVaultKeyAttribute>() // Let funchost know it's an Input binding, and how to convert it to the type the user specifies (eg: string). If you want the user to be able to use other types, you must add more 'BindToInput' calls that return those types as values. Here, I have to use a class implementing the IAsyncConverter because I need to call async methods to perform the conversion .BindToInput(KeyVaultKeyInputConverter.Instance) // Add a validator on the user's attribute implementation to make sure I can even do the conversion and blow up accordingly if I can't. .AddValidator((attrib, t) => { if (string.IsNullOrWhiteSpace(attrib.ResourceNameSetting)) { throw new ArgumentException(nameof(attrib.ResourceNameSetting)); } if (string.IsNullOrWhiteSpace(attrib.KeyIdSetting)) { throw new ArgumentNullException(nameof(attrib.KeyIdSetting)); } }); }
public void Initialize(ExtensionConfigContext context) { context.Trace.Info($"In {nameof(MyMessageExtensionConfigProvider)}.{nameof(Initialize)}"); context.AddConverter <string, MyMessage>(s => new MyMessage { Name = "Custom-binding (string): " + s } ); context.AddConverter <EventData, MyMessage>(s => { //var body = Encoding.UTF8.GetString(s.GetBytes()); //return new MyMessage { Name = "Custom-binding (EventData): " + body }; return(new MyMessage { Name = "Custom-binding (EventData): " + s.ToString() }); } ); }
public void Initialize(ExtensionConfigContext context) { // add converter between JObject and SlackMessage // Allows a user to bind to IAsyncCollector<JObject>, and the sdk will convert that to IAsyncCollector<SlackMessage> context.AddConverter <JObject, Container>(input => input.ToObject <Container>()); context.AddConverter <JObject, ContainerGroupDelete>(input => input.ToObject <ContainerGroupDelete>()); // Add a binding rule for Collector context.AddBindingRule <ContainerGroupAttribute>() .BindToCollector <Container>(attr => new ContainerCreateAsyncCollector(this, attr)); // Add a binding rule for Collector context.AddBindingRule <ContainerGroupWithPrivateRegistryAttribute>() .BindToCollector <Container>(attr => new ContainerCreateAsyncCollector(this, attr)); // Add a binding rule for Collector context.AddBindingRule <DeleteContainerGroupAttribute>() .BindToCollector <ContainerGroupDelete>(attr => new ContainerGroupDeleteAsyncCollector(this, attr)); }
private static IDependencyConfiguration InitializeContainer(ExtensionConfigContext context) { var configType = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(x => x.GetTypes()) .FirstOrDefault(x => typeof(IDependencyConfiguration).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract); IDependencyConfiguration configuration = null; if (configType == null) { return(configuration); } var configInstance = Activator.CreateInstance(configType); configuration = (IDependencyConfiguration)configInstance; return(configuration); }
public void Initialize(ExtensionConfigContext context) { context.AddBindingRule <TestStreamAttribute>(). BindToStream(this, FileAccess.ReadWrite); // Override the Stream --> String converter context.AddConverter <Stream, string>(stream => ReadTag); context.AddConverter <ApplyConversion <string, Stream>, object>((pair) => { var val = pair.Value; var stream = pair.Existing; using (var sr = new StreamWriter(stream)) { sr.Write("yy"); // custom sr.Write(val); } return(null); }); }
public void Initialize(ExtensionConfigContext context) { if (context == null) { throw new ArgumentNullException("context"); } _defaultAccountSid = _nameResolver.Resolve(AzureWebJobsTwilioAccountSidKeyName); _defaultAuthToken = _nameResolver.Resolve(AzureWebJobsTwilioAccountAuthTokenName); context.AddConverter <JObject, CreateMessageOptions>(CreateMessageOptions); var rule = context.AddBindingRule <TwilioSmsAttribute>(); rule.AddValidator(ValidateBinding); rule.BindToCollector <CreateMessageOptions>((attr) => { return(new TwilioSmsMessageAsyncCollector(CreateContext(attr))); }); }