Getting Started with DevAccelerate

Tanveer Yousuf edited this page Aug 9, 2018 · 4 revisions

Installing DevAccelerate Libraries

You can install DevAccelerate libraries by using NuGet Package Manager. To install all DevAccelerate libraries for example, simply follow these steps:

  1. Go to Tools > NuGet Package Manager > Package Manager Console.
  2. Execute the following command:
Install-Package DevAccelerateAll

Of course, you can install individual libraries if you want. You can see the complete list of DevAccelerate libraries by going to https://www.nuget.org/profiles/ejyle.

Configuration and Initialization

Provider model, configurability, and loose-coupling are at the heart of DevAccelerate design. This means bit of configuration and initialisation are required to make things work smoothly.

Loading Configuration Explicitly

The best place to load configuration and initialise some global objects in an ASP.NET web application is the Application_Start event in the Global.asax file.

At the top of the Global.asax file, import the following namespaces:

using Ejyle.DevAccelerate.Core;
using Ejyle.DevAccelerate.Core.Configuration;
using Ejyle.DevAccelerate.Core.Data.Configuration;
using Ejyle.DevAccelerate.Core.Caching.Configuration;
using Ejyle.DevAccelerate.Core.Exceptions.Configuration;
using Ejyle.DevAccelerate.Core.Logging.Configuration;
using Ejyle.DevAccelerate.Identity.AspNet.Configuration;
using Ejyle.DevAccelerate.Mail.Configuration;
using Ejyle.DevAccelerate.Sms.Configuration;

In the Application_Start method, write the following code:

/* Create default configuration source (web.config / app.config) */
var configurationSource = new DaDefaultConfigurationSource();

/* Load the DevAccelerate Data configuration */
DaDataConfigurationManager.InitConfiguration(ConfigurationSource);

/* Load the configuration for DevAccelerate ASP.NET identity */
DaIdentityConfigurationManager.InitConfiguration(configurationSource);
            
/* Load the configuration for DevAccelerate Mail and Sms */
DaMailConfigurationManager.SetConfiguration(configurationSource);
DaSmsConfigurationManager.SetConfiguration(configurationSource);

/* Load the configuration for DevAccelerate exception handling. */
DaCachingExceptionHandlingManager.InitConfiguration(configurationSource);

/* Load the configuration for DevAccelerate logging. */
DaCachingLoggingManager.InitConfiguration(configurationSource);

/* Load the configuration for DevAccelerate caching. */
DaCachingConfigurationManager.InitConfiguration(configurationSource);

If you intend to use Microsoft Enterprise Library wrappers for logging and exception handling purposes, you would need to bootstrap the Microsoft Enterprise Library in a similar fashion as well. If that is the case, you need to add the following code:

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;
// ...
DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory());
var mselConfigSource = ConfigurationSourceFactory.Create();
var mselExceptionPolicyFactory = new ExceptionPolicyFactory(mselConfigSource);
Logger.SetLogWriter(new LogWriterFactory(mselConfigSource).Create());
ExceptionPolicy.SetExceptionManager(mselExceptionPolicyFactory.CreateManager()); 

Defining Configuration in the Web.config File

Before you can write the actual code for caching, logging, and exception handling, you need to define the basic configuration of DevAccelerate.Core in the web.config file. Keep in mind, DevAccelerate especially the Core library is configuration-centric and you need to specify what implementation you want for which functionality. The following is example of how you would do it for caching, logging and exception handling:

<configSections>
    <section name="daCachingConfiguration" type="Ejyle.DevAccelerate.Core.Caching.Configuration.DaCachingConfigurationSection, DevAccelerate.Core" />
    <section name="daExceptionHandlingConfiguration" type="Ejyle.DevAccelerate.Core.Exceptions.Configuration.DaExceptionHandlingConfigurationSection, DevAccelerate.Core" />
    <section name="daLoggingConfiguration" type="Ejyle.DevAccelerate.Core.Logging.Configuration.DaLoggingConfigurationSection, DevAccelerate.Core" />
    <section name="daIdentityConfiguration" type="Ejyle.DevAccelerate.AspNet.Identity.Configuration.DaIdentityConfigurationSection, DevAccelerate.Identity.AspNet" />
    <section name="daMailConfiguration" type="Ejyle.DevAccelerate.Mail.Configuration.DaMailConfigurationSection, DevAccelerate.Mail" />
    <section name="daSmsConfiguration" type="Ejyle.DevAccelerate.Sms.Configuration.DaSmsConfigurationSection, DevAccelerate.Sms" />
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />    
</configSections>
  <daIdentityConfiguration>
    <twoFactorPolicy isEnabled="false" />
    <userNamePolicy isEnabled="false" allowOnlyAlphanumericUserNames="true" requireUniqueEmail="true" />
    <passwordPolicy isEnabled="false" minRequiredLength="6" requireSpecialCharacters="true" requireDigits="true" requireLowerCase="true" requireUpperCase="true" />
    <userLockoutPolicy isEnabled="true" defaultLockoutTimeSpan="5" userLockoutEnabledByDefault="false" maxFailedAccessAttemptsBeforeLockout="5" />
  </daIdentityConfiguration>
  <daMailConfiguration defaultProvider="sendGridProvider" defaultSenderName="My Team" defaultSenderEmail="info@example.com">
    <providers>
      <add name="sendGridProvider" type="Ejyle.DevAccelerate.Mail.SendGrid.DaSendGridMailProvider,DevAccelerate.Mail.SendGrid" apiKey="####" />
    </providers>
  </daMailConfiguration>
  <daSmsConfiguration defaultProvider="twilioProvider">
    <providers>
      <add name="twilioProvider" type="Ejyle.DevAccelerate.Sms.Twilio.DaTwilioSmsProvider,DevAccelerate.Sms.Twilio" sid="###" from="###" />
    </providers>
  </daSmsConfiguration> 
  <daCachingConfiguration defaultProvider="defaultCacheProvider">
    <providers>
      <add name="defaultCacheProvider" type="Ejyle.DevAccelerate.Core.Caching.DaDefaultCacheManager, DevAccelerate.Core" />
    </providers>
  </daCachingConfiguration>
  <daExceptionHandlingConfiguration defaultProvider="defaultExceptionHandler">
    <providers>
      <add name="defaultExceptionHandler" type="Ejyle.DevAccelerate.Core.ExceptionHandling.Msel.MselExceptionManager, DevAccelerate.Core.ExceptionHandling.Msel" />
    </providers>
  </daExceptionHandlingConfiguration>
  <daLoggingConfiguration defaultProvider="defaultLogManager">
    <providers>
      <add name="defaultLogManager" type="Ejyle.DevAccelerate.Core.Logging.Msel.MselLogManager, DevAccelerate.Core.Logging.Msel" />
    </providers>
  </daLoggingConfiguration>  
  <dataConfiguration defaultDatabase="daDbConnection" />

In the above configuration, Microsoft Enterprise Library implementation of logging and exception handling is used. For configuring and using Microsoft Enterprise Library implementation for logging and exception handling, please refer the projects MSEL Logging for DevAccelerate and MSEL Exception Handling for DevAccelerate.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.