Skip to content

Latest commit

 

History

History
223 lines (159 loc) · 6.8 KB

File metadata and controls

223 lines (159 loc) · 6.8 KB

PowerCSharp.Core

PowerCSharp Banner

PowerCSharp.Core License: MIT NuGet NuGet Downloads

The foundational core of the PowerCSharp ecosystem, providing centralized interfaces, models, and base functionality for all PowerCSharp packages. This package has been refactored to provide a clean, dependency-free foundation with improved architectural separation.

📦 Package Information

  • Package ID: PowerCSharp.Core
  • Version: 0.3.0
  • Target Frameworks: .NET 8.0, .NET Standard 2.0
  • Dependencies: None (dependency-free)

🏗️ Architecture Overview

PowerCSharp.Core serves as the architectural foundation for the entire PowerCSharp ecosystem:

Centralized Interfaces

All interfaces are centralized in PowerCSharp.Core to maintain proper architectural separation:

  • PowerCSharp.Core.Interfaces.Extensions.Configuration - Configuration-related interfaces
  • PowerCSharp.Core.Interfaces.Extensions.Linq - LINQ and dynamic query interfaces
  • PowerCSharp.Core.Interfaces.Models - Model classes (reserved for future use)

Benefits

  • Single source of truth for contracts and abstractions
  • Consistent namespace organization across packages
  • Easy dependency management across the ecosystem
  • Clear architectural boundaries between packages

🚀 Installation

dotnet add package PowerCSharp.Core

📚 Available Interfaces

Configuration Interfaces

IAppOptions

Namespace: PowerCSharp.Core.Interfaces.Extensions.Configuration

Represents the interface for application options.

public interface IAppOptions
{
    string ConfigSectionPath { get; }
}

Usage Example:

using PowerCSharp.Core.Interfaces.Extensions.Configuration;

public class MyAppOptions : IAppOptions
{
    public string ConfigSectionPath => "MyApp";
    public string ApiKey { get; set; }
    public int Timeout { get; set; }
}

LINQ & Dynamic Query Interfaces

IDynamicFilterProvider

Namespace: PowerCSharp.Core.Interfaces.Extensions.Linq

Implement a Service Provider for dynamically filtering of the type T using Dynamic Expressions.

public interface IDynamicFilterProvider<T>
{
    void SetFilter(Func<T, bool> filter);
    Func<T, bool> GetFilter();
}

IDynamicOrderProvider

Namespace: PowerCSharp.Core.Interfaces.Extensions.Linq

Implement a Service Provider for dynamically ordering of the type T using Dynamic Expressions.

public interface IDynamicOrderProvider<T>
{
    void SetOrderDelegates(List<(Func<T, object>, bool)> delegates);
    List<(Func<T, object>, bool)> GetOrderDelegates();
}

Usage Example:

using PowerCSharp.Core.Interfaces.Extensions.Linq;

// Create a dynamic filter provider
var filterProvider = new DynamicFilterProvider<Person>();
filterProvider.SetFilter(person => person.Age > 18 && person.Name.Contains("John"));

// Create a dynamic order provider
var orderProvider = new DynamicOrderProvider<Person>();
orderProvider.SetOrderDelegates(new List<(Func<Person, object>, bool)>
{
    (person => person.Name, false),  // Ascending by Name
    (person => person.Age, true)     // Descending by Age
});

🔗 Package Dependencies

PowerCSharp.Core has no external dependencies, making it lightweight and ideal for inclusion in any project.

Other PowerCSharp packages reference PowerCSharp.Core for:

  • Shared interfaces and contracts
  • Common base types
  • Architectural consistency

🎯 Use Cases

When to Use PowerCSharp.Core

  • Building custom PowerCSharp extensions that need to implement standard interfaces
  • Creating applications that use multiple PowerCSharp packages
  • Developing libraries that need to integrate with PowerCSharp ecosystem
  • Ensuring type safety across PowerCSharp packages

Integration Examples

With PowerCSharp.Extensions

using PowerCSharp.Extensions;
using PowerCSharp.Core.Interfaces.Extensions.Linq;

// Your custom filter implementation
public class PersonFilterProvider : IDynamicFilterProvider<Person>
{
    private Func<Person, bool> _filter;

    public void SetFilter(Func<Person, bool> filter) => _filter = filter;
    public Func<Person, bool> GetFilter() => _filter ?? (p => true);
}

// Use with PowerCSharp.Extensions
var people = new List<Person>();
var filtered = people.Filter(new PersonFilterProvider());

With Configuration

using Microsoft.Extensions.Configuration;
using PowerCSharp.Extensions;
using PowerCSharp.Core.Interfaces.Extensions.Configuration;

public class DatabaseOptions : IAppOptions
{
    public string ConfigSectionPath => "Database";
    public string ConnectionString { get; set; }
    public int Timeout { get; set; }
}

// Usage in application
var config = new ConfigurationBuilder().Build();
var dbOptions = config.GetOptions<DatabaseOptions>("Database");

🧪 Testing

PowerCSharp.Core includes comprehensive unit tests. Run tests with:

dotnet test src/PowerCSharp.Core.Tests

📖 Documentation

🤝 Contributing

Contributions are welcome! Please read our Contributing Guidelines for details.

Development Setup

  1. Clone the repository
  2. Navigate to PowerCSharp.Core project
  3. Run tests to ensure everything works
  4. Make your changes
  5. Add tests for new functionality
  6. Submit a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🔗 Related Packages

📞 Support


PowerCSharp.Core - The foundation of powerful C# development! 🚀

← Back to Main Documentation