Skip to content

010227leo/Hangerd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hangerd

Join the chat at https://gitter.im/010227leo/Hangerd

Build status

A lightweight and efficient .NET based application development framework. It provides the fundamental libraries and tools for practicing and implementing Domain-Driven Design.

Components

  • Hangerd
  • Hangerd.EntityFramework
  • Hangerd.Mongodb
  • Hangerd.Mvc

Dependencies

  • Unity v3.5.1404.0
  • Newtonsoft.Json v6.0.1

Usage

  • How to start
protected void Application_Start(object sender, EventArgs e)
{
	HangerdFramework.Start();
}

protected void Application_End()
{
	HangerdFramework.End();
}
  • IoC
public class RegisterServiceTask : RegisterServiceBootstrapperTask
{
	public RegisterServiceTask(IUnityContainer container) : base(container) { }

	public override void Execute()
	{
		IocContainer.RegisterTypeAsSingleton<IMyService, MyService>();
	}
}

static void Main(string[] args)
{
	var myService = LocalServiceLocator.GetService<IMyService>();
}
  • Domain model
public abstract class Account : EntityBase, IDeletable
{
	public string LoginName { get; private set; }

	public bool IsDeleted { get; set; }

	protected Account(string loginName)
	{
		if (string.IsNullOrWhiteSpace(loginName))
			throw new HangerdException("LoginName can not be null");

		LoginName = loginName;
	}
}
  • Domain event & Event handler
public class AccountNameModifiedEvent : DomainEvent
{
	public AccountNameModifiedEvent(Account account)
		: base(account)
	{ }
}

public class AccountNameModifiedEventHandler : IDomainEventHandler<AccountNameModifiedEvent>
{
	public void Handle(AccountNameModifiedEvent e)
	{
		var account = e.Source as Account;

		account.LastModified = DateTime.Now;
	}
}

public class RegisterServiceTask : RegisterServiceBootstrapperTask
{
	public RegisterServiceTask(IUnityContainer container) : base(container) { }

	public override void Execute()
	{
		IocContainer.RegisterMultipleTypesAsPerResolve<IDomainEventHandler<AccountNameModifiedEvent>, AccountNameModifiedEventHandler>();
	}
}
	
public void ModifyName(string name)
{
	Name = name;

	DomainEvent.Publish(new AccountNameModifiedEvent(this));
}

About

hanger for ddd

Resources

Stars

Watchers

Forks

Packages

No packages published