Book
This chapter provides a narrative guide to the Energy.Core library.
Code at first sight
Energy.Core is designed to reduce boilerplate. The namespaces are organized by responsibility:
Energy.Base— low-level utilities and conversions.Energy.Core— application framework, workers, logging, and networking.Energy.Source— database connections and schema.Energy.Query— SQL generation.Energy.Attribute— metadata attributes.Energy.Interface— contracts.Energy.Enumeration— shared enumerations.
When starting a new project, import the Energy.Core namespace and use fully qualified names for Energy.Enumeration or alias it:
using Energy.Core;
using Energy.Base;
using EE = Energy.Enumeration;
Case: Service
A Windows service or background worker can use Energy.Core.Worker<T> to manage long-running threads.
public class MyService : Worker<object>
{
public override void Work()
{
while (!Stopped)
{
// do work
Sleep(1000);
}
}
}
Use Energy.Core.Log to write to the file system or console.
Case: Application
A console application can implement Energy.Interface.ICommandProgram and use Energy.Core.Application to run the lifecycle.
public class MyProgram : ICommandProgram
{
public bool Setup(string[] args) { return true; }
public bool Initialize(string[] args) { return true; }
public bool Run(string[] args) { return true; }
}
Borrow, play, throw away
Use the library as you like. Many helpers are independent and can be copied or used without the full framework.
Coding tips
Prefer fully qualified names or aliases for enumerations to avoid name conflicts.
Use
Energy.Base.Castfor safe international conversions.Use
Energy.Base.Textfor string manipulation.Use
Energy.Base.Collection.StringDictionaryfor configuration maps.Use
Energy.Core.Logfor structured logging.Implement
Energy.Interface.ILoggerfor custom log destinations.