Skip to content

Instantly share code, notes, and snippets.

@hagbarddenstore
Created November 14, 2013 15:59
Show Gist options
  • Save hagbarddenstore/7469259 to your computer and use it in GitHub Desktop.
Save hagbarddenstore/7469259 to your computer and use it in GitHub Desktop.
// In BusinessLayer.dll
using System;
public class User
{
public User(string username)
{
Id = Guid.NewGuid();
CreatedOn = DateTime.UtcNow;
Username = username;
}
public Guid Id { get; private set; }
public DateTime CreatedOn { get; private set; }
public string Username { get; private set; }
public void Rename(string username)
{
// ...
}
}
public interface IUsersRepository
{
User Find(Guid id);
void Save(User user);
}
// In DataLayer.dll
using System;
using MongoDB.Bson.Serialization;
public class UserMap : BsonClassMap<User>
{
public UserMap()
{
Id(x => x.Id);
MapProperty(x => x.CreatedOn);
MapProperty(x => x.Username);
}
}
public class MongoDbUsersRepository : IUsersRepository
{
public User Find(Guid id)
{
// ...
}
public void Save(User user)
{
// ...
}
}
// In Application.exe
public class Program
{
public static void Main()
{
// TODO: Use IoC/DI to find implementations...
var usersRepository = new MongoDbUsersRepository();
var user = new User("Kim^J");
usersRepository.Save(user);
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment