This project demonstrates the use of the Managed Extensibility Framework (MEF) in a production environment. It showcases how MEF can be leveraged to create a modular, extensible architecture for processing payroll operations, making it easy to add new features and components without modifying the core system.
The solution is organized into several key projects, each serving a specific purpose:
-
Interfaces
Contains core interfaces.
EntitiesICompanyIState
BusinessObjectsIPayrollRegistration
-
Models
Houses implementations of Interfaces.
EntitiesCountryState
BusinessObjectsPayrollRegistration
-
PayrollProcessor
Provides implementation of payroll system. Its in here that we import
IPayrollRegistrationobjects and process them based on commandsIPayrollServicePayrollService
-
RegistrationAtLaunch
Its in here that we registered companies for payroll service. For the sake for this demo, This is what we will assume that was shipped when initially deployed. We register an entry for each Company and the TaxState we wanted to process the payroll So if we want a company names "First Company" to have payroll processed in states "First State" and "Second State" we register them as follows
[Export(typeof(IPayrollRegistration))] public class FirstCompanyFirstState : PayrollRegistration { public FirstCompanyFirstState() : base("First Company", "First State") { } public override void RunPayrollForCompany(ICompany company, IState state) { // This will be where Company and State specific Payroll processing be implemented Console.WriteLine($"Running custom payroll for {company.Name} in state {state.Name}."); } } [Export(typeof(IPayrollRegistration))] public class FirstCompanySecondState : PayrollRegistration { public FirstCompanySecondState() : base("First Company", "Second State") { } public override void RunPayrollForCompany(ICompany company, IState state) { // This will be where Company and State specific Payroll processing be implemented Console.WriteLine($"Running custom payroll for {company.Name} in state {state.Name}."); } }
-
Prerequisites
- .NET SDK (version 4.7.2 or higher)
- Visual Studio or another compatible IDE
-
Build Steps
- Clone the repository:
git clone https://github.com/sreee2001/MEF-Enabled-Payroll-Management-Mock-Demo.git - Open the solution in Visual Studio.
- Restore NuGet packages and build the solution (
Build > Build Solution).
- Clone the repository:
-
Deploying Binaries
- Run the
PayrollManagement.UIproject to launch the demo application. - Compiled binaries will be located in the
/bin/Debugor/bin/Releasefolder in the Solution Directory. Note: I have changed the build output path.
- Run the
To expand the system using MEF:
-
Create a New Plugin Project
- Add a new Class Library project to the solution.
- Reference
InterfacesandModels.
-
Implement Required Interfaces and Export Components with MEF
-
Create classes that implement
PayrollRegistrationand Export them as typeIPayrollRegistration. -
Use the
[Export]attribute to mark your classes as MEF components. -
For Example to add additional payroll registration, say for Adidas in California
-
use the following code:
[Export(typeof(IPayrollRegistration))] public class AdidasCalifornia : PayrollRegistration { public AdidasCalifornia() : base("Adidas", "California") { } public override void RunPayrollForCompany(ICompany company, IState state) { // This will be where Company and State specific Payroll processing be implemented Console.WriteLine($"Running custom payroll for {company.Name} in state {state.Name}."); } }
-
-
Deploy Plugins
- Place the compiled plugin DLL in the designated plugins folder recognized by the UI which is
$(SolutionDir)/bin/Debugor$(SolutionDir)/bin/Release. - Restart the application; MEF will discover and load the new plugin automatically.
- Place the compiled plugin DLL in the designated plugins folder recognized by the UI which is
-
Sample Implementation
- PhaseOneExtension is a library that is added after the entire code is deployed. If manually deploying this project, copy the dll to where the application is installed and scanning. Restart the application
- It only contains example of additional workloads
- Company : Adidas , States : California, Texas and Utah
- Company : Walmart, States : Texas, Florida and Ohio
- It only contains example of additional workloads
- PhaseOneExtension is a library that is added after the entire code is deployed. If manually deploying this project, copy the dll to where the application is installed and scanning. Restart the application
- When the appliaction is run, it will detect this additional dll and load it and with it the above workflows will be available
- To test further, go to the deployment location, manually delete this dll and restart the application. It will revert to the original options