Git Product home page Git Product logo

classicdomain's Introduction

ClassicDomain C# Driver

You can get the latest stable release from the official Nuget.org feed.

Getting Started

MongoDB Sample

You need to download MongoDB.

web.config or app.config

<connectionStrings>
	<add name="Sample.Repositories.Mapping" connectionString="mongodb://localhost/Sample?journal=true" />
</connectionStrings>

Domain

namespace Sample.Domain
{
	public class Person
	{
		public Guid Id { get; private set; }

		public string FirstName { get; private set; }

		public string LastName { get; private set; }

		private Person() { }

		public static Person Create(string firstName, string lastName)
		{
			var result = new Person();
			result.FirstName = firstName;
			result.LastName = lastName;
			return result;
		}

		public void Change(string firstName, string lastName)
		{
			FirstName = firstName;
			LastName = lastName;
		}
	}
}

Repositories

using Oldmansoft.ClassicDomain;
namespace Sample.Repositories
{
	class Mapping : Oldmansoft.ClassicDomain.Driver.Mongo.Context
	{
		protected override void OnModelCreating()
		{
			Add<Domain.Person, Guid>(o => o.Id)
				.SetUnique(g => g.CreateGroup(o => o.LastName).Add(o => o.FirstName));
		}
	}
}
namespace Sample.Infrastructure
{
    public interface IPersonRepository : Oldmansoft.ClassicDomain.IRepository<Domain.Person, Guid>
    {
        Oldmansoft.ClassicDomain.IPagingData<Domain.Person> PageByName();

        Domain.Person GetByName(string firstName, string lastName);
    }
}
namespace Sample.Repositories
{
    class PersonRepository : Oldmansoft.ClassicDomain.Driver.Mongo.Repository<Domain.Person, Guid, Mapping>, Infrastructure.IPersonRepository
    {
        public PersonRepository(UnitOfWork uow)
            : base(uow)
        { }

        public Oldmansoft.ClassicDomain.IPagingData<Domain.Person> PageByName()
        {
            return Query().Paging().OrderBy(o => o.LastName).ThenBy(o => o.FirstName);
        }

        public Domain.Person GetByName(string firstName, string lastName)
        {
            return Query().FirstOrDefault(o => o.LastName == lastName && o.FirstName == firstName);
        }
    }
}
using Oldmansoft.ClassicDomain;
namespace Sample.Repositories
{
	public class RepositoryFactory
	{
		private UnitOfWork Uow { get; set; }

		public RepositoryFactory()
		{
			Uow = new UnitOfWork();
		}

		public IUnitOfWork GetUnitOfWork()
		{
			return Uow;
		}

		public Infrastructure.IPersonRepository CreatePerson()
		{
			return new PersonRepository(Uow);
		}
	}
}

Add Domain To Repository

using Oldmansoft.ClassicDomain;
namespace Sample
{
	class Program
	{
		static void Main(string[] args)
		{
			var factory = new Repositories.RepositoryFactory();
			var repository = factory.CreatePerson();
			var domain = Domain.Person.Create("firstName", "lastName");
			repository.Add(domain);
			factory.GetUnitOfWork().Commit();
		}
	}
}

Replace Domain From Repository

using Oldmansoft.ClassicDomain;
namespace Sample
{
	class Program
	{
		static void Main(string[] args)
		{
			var factory = new Repositories.RepositoryFactory();
			var repository = factory.CreatePerson();
			var domain = repository.GetByName("firstName", "lastName");
			domain.Change("first", "last");
			repository.Replace(domain);
			factory.GetUnitOfWork().Commit();
		}
	}
}

Remove Domain From Repository

using Oldmansoft.ClassicDomain;
namespace Sample
{
	class Program
	{
		static void Main(string[] args)
		{
			var factory = new Repositories.RepositoryFactory();
			var repository = factory.CreatePerson();
			var domain = repository.GetByName("firstName", "lastName");
			repository.Remove(domain);
			factory.GetUnitOfWork().Commit();
		}
	}
}

Maintainers:

If you have contributed and we have neglected to add you to this list please contact one of the maintainers to be added to the list (with apologies).

classicdomain's People

Contributors

oldmansoft avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.