Architecture design and implementation for an analytics engine manager. Incorporates the extensibility and reusability software design principles to allow the addition of new analytics engines. The code is also testable and comes with a suite of unit tests.
An analytics engine provides the means of logging and propagating an event to the cloud. The code has a working example using Azure Application Insights.
Set
ApplicationInsightsInstrumentationKey
inApp.config
to the resource instrumentation key.
Set
ApplicationInsights
inApp.config
totrue
if tracking events,false
otherwise.
Install-Package Microsoft.ApplicationInsights -Version 2.8.1
This would require you to register the following mappings to the DI container:
ICustomConfigurationManager
toCustomConfigurationManager
IAnalyticsEnginesFactory
toAnalyticsEnginesFactory
IAnalyticsEventProcessor
toAnalyticsEventProcessor
Making them a singleton would mean that only a single object is created per project, this is fine, however, if Analytics Engine Manager, for example, is used by multiple endpoints, then all endpoints are dependent on a single resource. Usually this is not ideal.
string eventName = "";
string userID = "";
string remoteIPAddress = "";
IAnalyticsEvent analyticsEvent = new AnalyticsEvent(eventName, userID, remoteIpAddress);
AnalyticsEventProcessor.LogEvent(analyticsEvent);
string eventName = "";
string userID = "";
string remoteIPAddress = "";
IAnalyticsEvent analyticsEvent = new AnalyticsEvent(eventName, userID, remoteIpAddress);
ICustomConfigurationManager analyticsConfigurationManager = new CustomConfigurationManager();
IAnalyticsEnginesFactory analyticsEnginesFactory = new AnalyticsEnginesFactory();
IAnalyticsEventProcessor analyticsEventProcessor = new AnalyticsEventProcessor(analyticsConfigurationManager, analyticsEnginesFactory);
analyticsEventProcessor.LogEvent(analyticsEvent);
First, create a concrete class for the new Analytics Engine.
/// <summary>
/// Create a concrete class for the new Analytics Engine.
/// Implement the IAnalyticsEngine interface.
/// </summary>
public class MyAnalyticsEngine : IAnalyticsEngine
{
public string GetAnalyticsEngineName { get; private set; }
public void SendEvent(IAnalyticsEvent analyticsEvent)
{
// Send analyticsEvent to the cloud.
}
}
Second, add the new concrete class to AnalyticsEnginesFactory
.
public class AnalyticsEnginesFactory : IAnalyticsEnginesFactory
{
public List<IAnalyticsEngine> CreateAnalyticsEngines(ICustomConfigurationManager analyticsConfigurationManager)
{
List<IAnalyticsEngine> analyticsEngines = new List<IAnalyticsEngine>();
analyticsEngines.Add(new ApplicationInsightsAnalyticsEngine(analyticsConfigurationManager));
// Add an instance of the new concrete class to the list of Analytics Engines
analyticsEngines.Add(new MyAnalyticsEngine(analyticsConfigurationManager));
return analyticsEngines;
}
}