Skip to content

TimmyGray/BuyingLibrary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BuyingLibrary

A .NET 10 class library that provides shared MongoDB models, services, and configuration options for the Dotnet_Server back-end of the BuyingLibrary cable-shop platform.


Project context

The platform has two independent parts:

Part Repositories
Seller Lovely_Wires · Lovely_wires_server
Customer Buying_Client · Dotnet_Server · BuyingLibrary (this repo)

Both parts share the same MongoDB instance.


Architecture overview

BuyingLibrary
├── AppSettings/            Configuration option classes (bound via IOptions<T>)
│   ├── ConnectionStringsOptions
│   ├── DataBaseOptions
│   └── MailOptions
├── Actions/
│   └── DeserAction         Polymorphic BSON deserialiser (Coil vs Connector)
├── Contexts/               MongoDB services
│   ├── MongoContext        Singleton – holds all collection/GridFS handles
│   ├── IService<T>         Generic CRUD contract
│   ├── BuyingService       buys collection
│   ├── ClientService       clients collection
│   ├── CoilService         coils collection
│   ├── ConnectorService    connectors collection
│   ├── ImageService        GridFS imagestore bucket
│   ├── OrderService        orders collection
│   └── PriceService        prices collection (raw BsonDocument)
└── models/
    ├── classes/            Domain models (Buy, BuyImage, Client, Coil, Connector,
    │                       Item, Order, Price, Wire, WireBuy)
    ├── enums/              OrderStatus, ConnectorType
    └── interfaces/         IActions<T>, IOrder

Prerequisites

Requirement Version
.NET SDK 10.0 or later
MongoDB 6.0 or later

Getting started

1 — Clone and build

git clone https://github.com/TimmyGray/BuyingLibrary.git
cd BuyingLibrary
dotnet build

2 — Reference from the server project

Add a <ProjectReference> to your server .csproj:

<ItemGroup>
  <ProjectReference Include="..\BuyingLibrary\BuyingLibrary.csproj" />
</ItemGroup>

3 — Configure appsettings.json

{
  "DataBaseSettings": {
    "DataBaseConnection": "mongodb://localhost:27017",
    "DataBase": "buyingdb"
  },
  "ConnectionStrings": {
    "AppUrl":    "http://localhost:5000",
    "ClientUrl": "http://localhost:3000"
  },
  "EmailSettings": {
    "Email":    "sender@example.com",
    "Password": "secret",
    "Host":     "smtp.example.com",
    "Port":     587,
    "Name":     "BuyingLibrary Shop"
  }
}

4 — Register services in Program.cs

using BuyingLibrary.AppSettings;
using BuyingLibrary.Contexts;

// Bind configuration sections
builder.Services.Configure<DataBaseOptions>(
    builder.Configuration.GetSection(DataBaseOptions.DataBaseSettings));
builder.Services.Configure<ConnectionStringsOptions>(
    builder.Configuration.GetSection(ConnectionStringsOptions.ConnectionStrings));
builder.Services.Configure<MailOptions>(
    builder.Configuration.GetSection(MailOptions.EmailSettings));

// Register the MongoDB context (singleton – one connection pool per process)
builder.Services.AddSingleton<MongoContext>();

// Register services (add only the ones you need)
builder.Services.AddScoped<IService<Buy>, BuyingService>();
builder.Services.AddScoped<IService<Client>, ClientService>();
builder.Services.AddScoped<IService<Coil>, CoilService>();
builder.Services.AddScoped<IService<Connector>, ConnectorService>();
builder.Services.AddScoped<IService<Order>, OrderService>();
builder.Services.AddScoped<IService<BsonDocument>, PriceService>();
builder.Services.AddScoped<ImageService>();
builder.Services.AddScoped<DeserAction>();

Services reference

Service Collection Notes
BuyingService buys GetAsync() returns only non-custom buys
ClientService clients PostAsync is idempotent — returns existing client if e-mail matches
CoilService coils Full CRUD
ConnectorService connectors Full CRUD
OrderService orders Extra methods: GetByClientAsync, GetByClientAndOrderAsync
PriceService prices Returns raw BsonDocument; use DeserAction to resolve the item
ImageService GridFS imagestore GetAllAsync loads all images into memory; GetOneAsync streams to a Stream

Configuration options reference

DataBaseOptions (DataBaseSettings)

Property Type Description
DataBaseConnection string MongoDB connection string
DataBase string Database name

ConnectionStringsOptions (ConnectionStrings)

Property Type Description
AppUrl string URL the server listens on
ClientUrl string Front-end origin used for CORS

MailOptions (EmailSettings)

Property Type Description
Email string Sender address
Password string SMTP password
Host string SMTP hostname
Port int SMTP port (e.g. 587)
Name string Display name in From header

Stack

Technology Version
C# 13 (latest)
.NET 10 LTS
MongoDB.Driver 3.8
Microsoft.Extensions.* 10.0

Known limitations / roadmap

  • Wire and WireBuy are placeholder models for a future fully-assembled cable catalogue feature.
  • ImageService.GetAllAsync downloads all images into memory at once. For large catalogues, a streaming/pagination approach should be added.
  • No unit tests yet — a test project targeting xUnit is planned.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages