Skip to content

This project has been developed with the .NET Standard 2.1. It allows you to call stored procedures from the database by simply creating only interface and methods signatures without needing any concrete class to call any stored procedure.

License

Notifications You must be signed in to change notification settings

bariscantanriverdi/BctSP

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BctSP

This project has been developed with the .NET Standard 2.1. It allows you to call stored procedures from the database by simply creating only the interface and methods signature without needing any concrete class to call any stored procedure. It can work async and sync. It provides stored procedure support for MsSQL and MySQL and function support for PostgreSQL.

Installation

BctSP is now available on NuGet. If interested, you can easily install it using the NuGet Package Manager. It can be accessed through the link https://www.nuget.org/packages/BctSP.

Usage

To utilize the BctSP NuGet package, you can follow these phases:

  • Add BctSP service to your application builder in Program.cs and set BctSpConnectionStringOrConfigurationPath and DatabaseType for database connection, which can be MsSQL, MySQL, or PostgreSQL.
builder.Services.AddBctSp((x) =>
{
    // x.BctSpConnectionStringOrConfigurationPath = "Server=...";
    x.BctSpConnectionStringOrConfigurationPath = "Databases:ConnectionString";
    x.DatabaseType = BctSpDatabaseType.PostgreSql;
});
  • Create a request that inherits from the BctSpBaseRequest. The generic argument of the BctSpBaseRequest should be the response type of the request that inherits BctSpBaseResponse.
    public class GetProductsByPriceRequest : BctSpBaseRequest<GetProductsByPriceResponse>
    {
        public GetProductsByPriceRequest(string bctSpName) : base(bctSpName)
        {
        }

        public decimal ProductPrice { get; set; }

    }
  • Create a response that inherits from the BctSpBaseResponse.
	public class GetProductsByPriceResponse : BctSpBaseResponse
	{

		public string ProductName { get; set; }

		public decimal ProductPrice { get; set; }

		public string ProductDescription { get; set; }
	}
  • Create an interface that implements IBctSp and has method signatures.
	public interface ISampleSP : IBctSp
	{
	 
		List<GetProductsByPriceResponse> GetProductsByPrice(GetProductsByPriceRequest request);
	 
		Task<List<GetProductsByPriceResponse>> GetProductsByPriceAsync(GetProductsByPriceRequest request);

	}
  • Get the interface with the Dependency Injection pattern.
public class WeatherForecastController
{
    private readonly ISampleSP _sampleSp;

    public WeatherForecastController(ISampleSP sampleSp)
    {
        _sampleSp = sampleSp;
    }

Sample Usage

        public List<GetProductsByPriceResponse> GetProductsByPrice()
        {
            var response = _sampleSp.GetProductsByPrice(new GetProductsByPriceRequest("yourSPname") { ProductPrice = 100 });

            return response;
        }

        public async Task<List<GetProductsByPriceResponse>> GetProductsByPriceAsync()
        {
            var response = await _sampleSp.GetProductsByPriceAsync(new GetProductsByPriceRequest("yourSPname") { ProductPrice = 100 });

            return response;
        }

Customized Usage
The database configuration can be overridden and customized for each request if needed.

    public List<GetProductsByPriceResponse> GetProductsByPrice()
    {
        var response = _sampleSp.GetProductsByPrice(
            new GetProductsByPriceRequest("yourSPname",
                "CustomDatabases:ConnectionString",
                BctSpDatabaseType.MsSql) { ProductPrice = 100 });

        // var response = _sampleSp.GetProductsByPrice(
        //     new GetProductsByPriceRequest("yourSPname",
        //         "Server=...",
        //         BctSpDatabaseType.MsSql) { ProductPrice = 100 });

        return response;
    }
    
    public async Task<List<GetProductsByPriceResponse>> GetProductsByPriceAsync()
    {
        var response = await _sampleSp.GetProductsByPriceAsync(
            new GetProductsByPriceRequest("yourSPname",
                "CustomDatabases:ConnectionString",
                BctSpDatabaseType.MsSql) { ProductPrice = 100 });

        // var response = await _sampleSp.GetProductsByPriceAsync(
        //     new GetProductsByPriceRequest("yourSPname",
        //         "Server=...",
        //         BctSpDatabaseType.MsSql) { ProductPrice = 100 });

        return response;
    }

Contact Me:   - LinkedIn   -   Mail


About

This project has been developed with the .NET Standard 2.1. It allows you to call stored procedures from the database by simply creating only interface and methods signatures without needing any concrete class to call any stored procedure.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%