Base solution for your next web application
Open Closed

Adding IAppNotifier to a 3rd party application #9886


User avatar
0
devinedon created

Currently running : ANZ 9.3

We currently heavily use Azure for our pipeline. We have logic within an Azure Function that does Azure Push Notifications so would love to also send to the web to notify users via AppNotifier here as well.

There is probably a much larger requirment but what is needed to push messages outside of web host? I am battling to access AppNotifier (Object reference).

The FunctionStartup Configuration - where I attempt to DI IAppNotifier? :shrug :

The function constructor:

Error within AppNotifier:

Any help would be appreciated. I am assuming Im misunderstanding a key understanding regarding the signalR notification system and what is possible.


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @devinedon

    Does your project contains an ABP Module class which contains the Azure Function ? You need to create a module as explained here https://aspnetboilerplate.com/Pages/Documents/Module-System

  • User Avatar
    0
    devinedon created

    Hey, thanks for the reply

    It seems like its still ongoing :/ https://github.com/abpframework/abp/issues/527 With Dependency Injection its now most likely possible for Azure Functions https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection

    Do you have any ideas how I could convert my azure function into an ABP Module? Here is my onConfigure so far

    `using Microsoft.Azure.Documents.Client; using Microsoft.Azure.Functions.Extensions.DependencyInjection; using Microsoft.Azure.WebJobs.Host.Bindings; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using SynapWare.Configuration; using SynapWare.CosmosDB; using SynapWare.Notifications; using System; using System.Collections.Generic;

    [assembly: FunctionsStartup(typeof(SynapWare.AzureFunction.IoT.Startup))] namespace SynapWare.AzureFunction.IoT { public class Startup : FunctionsStartup { private IConfigurationRoot _appConfiguration; private DocumentClient _documentClient;

        public override void Configure(IFunctionsHostBuilder builder)
        {
            var executioncontextoptions = builder.Services.BuildServiceProvider().GetService<IOptions<ExecutionContextOptions>>().Value;
            var currentDirectory = executioncontextoptions.AppDirectory;
            //_appConfiguration = AppConfigurations.Get(Environment.CurrentDirectory);
            _appConfiguration = AppConfigurations.Get(currentDirectory);
    
            var serviceEndpoint = new Uri(_appConfiguration.GetValue<string>("LatestDeviceDataCosmosDb:ServiceEndpoint"), UriKind.Absolute);
            var authKey = _appConfiguration.GetValue<string>("LatestDeviceDataCosmosDb:authKey");
            var databaseName = _appConfiguration.GetValue<string>("LatestDeviceDataCosmosDb:DatabaseName");
            var collectionName = _appConfiguration.GetValue<string>("LatestDeviceDataCosmosDb:CollectionName");
            var collectionNames = new List<string>();
            collectionNames.Add(collectionName);
    
            var jsonSer = new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                DefaultValueHandling = DefaultValueHandling.Ignore,
                ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }
            };
            _documentClient = new DocumentClient(serviceEndpoint, authKey, jsonSer);
            _documentClient.OpenAsync().Wait();
            var cosmosDbClientFactory = new CosmosDbClientFactory(databaseName, collectionNames, _documentClient);
            cosmosDbClientFactory.EnsureDbSetupAsync().Wait();
            builder.Services.AddSingleton<ICosmosDbClientFactory>(cosmosDbClientFactory);
    
            var connectionString = _appConfiguration.GetValue<string>("NotificationHubSettings:FullAccessConnectionString");
            var notificationHubPath = _appConfiguration.GetValue<string>("NotificationHubSettings:NotificationHubName");
            var notificationHub = new NotificationHubManager(connectionString, notificationHubPath);
            builder.Services.AddSingleton<INotificationHubManager>(notificationHub);
    
            //IocManager.RegisterAssemblyByConvention(typeof(Startup).GetAssembly());
            //builder.Services.AddSignalR();
            //builder.Services.AddHttpClient();
            ////endpoints.MapHub<AbpCommonHub>("/signalr");
            //builder.Services.AddSingleton<INotificationPublisher, NotificationPublisher>();
            //builder.Services.AddSingleton<IAppNotifier, AppNotifier>();
        }
    }
    

    } ` Assuming whatever magic will happen here. I need to register IoCManager manually?

    EDIT : Following Migrator project at the moment. Hopefully can sneak it into a using

    using (var bootstrapper = AbpBootstrapper.Create<ABCModule>())

  • User Avatar
    0
    ismcagdas created
    Support Team
  • User Avatar
    0
    devinedon created

    Got it working :) Like I stated in previous comment, answer lies within the migrator project. If anyone wants me to post some sample code let me know and I will do that.