{"id":15392978,"url":"https://github.com/pimbrouwers/lunchpail","last_synced_at":"2025-04-15T23:30:11.636Z","repository":{"id":64846464,"uuid":"142483661","full_name":"pimbrouwers/LunchPail","owner":"pimbrouwers","description":".NET Standard Unit of Work implementation for ADO.NET","archived":false,"fork":false,"pushed_at":"2022-12-15T23:54:16.000Z","size":45,"stargazers_count":38,"open_issues_count":1,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-07T13:38:52.416Z","etag":null,"topics":["ado","ado-net","ioc-container","repository-pattern","unit-of-work"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pimbrouwers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-26T19:13:27.000Z","updated_at":"2024-12-04T22:51:21.000Z","dependencies_parsed_at":"2022-12-16T20:51:30.072Z","dependency_job_id":null,"html_url":"https://github.com/pimbrouwers/LunchPail","commit_stats":null,"previous_names":["pimbrouwers/lunch-pail"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pimbrouwers%2FLunchPail","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pimbrouwers%2FLunchPail/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pimbrouwers%2FLunchPail/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pimbrouwers%2FLunchPail/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pimbrouwers","download_url":"https://codeload.github.com/pimbrouwers/LunchPail/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240356060,"owners_count":19788512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ado","ado-net","ioc-container","repository-pattern","unit-of-work"],"created_at":"2024-10-01T15:16:59.900Z","updated_at":"2025-04-15T23:30:11.616Z","avatar_url":"https://github.com/pimbrouwers.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# LunchPail\n[LunchPail](https://github.com/pimbrouwers/LunchPail) is a .NET Standard compliant Unit of Work implementation for ADO.NET. The UoW is the workhorse of the data context, so the project was dubbed \"lunch pail\" as a reference to blue collar athletes.\n\n[![NuGet Version](https://img.shields.io/nuget/v/LunchPail.svg)](https://www.nuget.org/packages/LunchPail)\n[![Build Status](https://travis-ci.org/pimbrouwers/LunchPail.svg?branch=master)](https://travis-ci.org/pimbrouwers/LunchPail)\n\n## Getting Started\n\n1. Register the context within your IoC container (.NET Core shown below using SQL Server):\n\n```c#\n//startup.cs\npublic void ConfigureServices(IServiceCollection services)\n{\n  //rest of code...\n\n  //context\n  services.AddTransient\u003cIDbConnectionFactory\u003e(options =\u003e\n  {\n    var builder = new SqlConnectionStringBuilder(Configuration.GetConnectionString(\"DefaultConnection\"));\n\n    return new DbConnectionFactory(() =\u003e\n    {\n      var conn = new SqlConnection(builder.ConnectionString);\n\n      conn.Open();\n      return conn;\n    });\n  });\n  services.AddScoped\u003cIDbContext, DbContext\u003e();\n\n  //repositories (we'll add this later)\n}\n```\n\n2. Create a domain class to represents your database object.\n\n```c#\npublic class Product\n{\n  public int Id { get; set; }\n  public string Name { get; set; }\n}\n```\n\n3. Create a repository with a dependency on `IDbContext`\n\n```c#\npublic interface IProductRepository\n{\n  Task\u003cProduct\u003e Read (int id);\n}\n\npublic class ProductRepository : DbRepository\n{\n  public ProductRepository(IDbContext dbContext) : base(dbContext) { }\n\n  public Product Read(int id)\n  {\n    return Connection.QuerySingleOrDefault\u003cProduct\u003e(\"select * from dbo.Product where Id = @id\", new { id }, transaction: Transaction);\n  }\n}\n```\n\n4. Register the repository with your IoC container (.NET Core shown below):\n\n```c#\n//startup.cs\npublic void ConfigureServices(IServiceCollection services)\n{\n  //repositories\n  services.AddScoped\u003cIProductRepository, ProductRepository\u003e();\n}\n```\n\n5. With the context and repository registered, you're free to inject this into your controller or service layer.\n\n```c#\npublic class ProductService\n{\n  private readonly IDbContext dbContext;\n  private readonly IProductRepository productRepository;\n\n  public ProductService (\n    IDbContext dbContext,\n    IProductRepository productRepository)\n  {\n    this.dbContext = dbContext;\n    this.productRepository = productRepository;\n  }\n\n  public Product Read(int id)\n  {\n    var product = productRepository.Read(id);\n    return product;\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpimbrouwers%2Flunchpail","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpimbrouwers%2Flunchpail","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpimbrouwers%2Flunchpail/lists"}