Code Monkey home page Code Monkey logo

lclframework's Introduction

LCLFramework

LCLFramework就是一套在.NET下支持面向领域驱动的软件系统管理类软件的快速开发框架

使用开发框架的好处:
1.框架在技术上为软件系统提供了完整的模式实践
2.框架为团队提供了合理可行的软件开发过程模式
3.框架的应用大大提高了团队的开发效率,团队只需要关注与领域相关的业务实现,而无需关注具体的技术实现
4.框架的应用大大降低了出现缺陷(Bug)的几率,因为大多数支撑业务系统的代码都经过了严格的测试和实战的考验
5.框架的应用还为软件系统的整合与集成带来了便捷

LCLFramework 框架简要说明:

LCLFramework就是一套在.NET下支持面向领域驱动的软件系统管理类软件的快速开发框架 ,其目标主要专注于:

  1. 快速开发:
    DDD、界面自动生成、数据库自动生成与升级、易用的业务逻辑编写框架。
  2. 产品线工程:
    插件化业务模块积累、客户化二次开发、实施配置平台。
  3. 一套代码,可同时生成并运行 C/S、单机版、B/S 三种应用程序。
    C/S版本 与 单机版 代码重用率 100%。
    C/S版本 与 B/S版本 重用服务端代码(完全重用服务层以下代码。结合界面生成,只需要编写少量的界面层控制代码即可)。

已完成:

1.基于NuGet Package Manager提供方便快捷的类库包发布方式,开发人员无需关心程序集之间的版本依赖关系
2.提供对领域驱动设计中基本元素的封装。比如:实体、聚合根、领域事件、领域服务、领域仓储、仓库规约等概念进行了有效的封装和实现
3.提供对现有流行框架的支持。比如:能够很好地支持ASP.NET MVC以及ASP.NET Web API的使用和开发
4.提供基于Microsoft Patterns & Practices Unity的IoC容器和服务定位器(Service Locator)的实现。不仅如此,开发人员还能根据项目的实际需求对IoC容器和服务定位器进行扩展,使其能够支持更多的Dependency Injection(DI)框架。比如可以很方便地扩展LCLFramework,使其能够支持基于StructureMap、Ninject等流行的DI框架
5.提供基于Entity Framework的仓储实现。在应用程序中使用这种仓储,也就基本涵盖了所有面向关系型数据库的对象持久化方案。不仅如此,开发人员还能根据项目的实际需求,对仓储实现进行扩展,以支持更多种类的对象持久化机制
6.提供简单的插件化业务模块积累和客户化二次开发

帮助手册:由于时间及人员的关系,现在还没有发布可用的使用说明。我之后会陆续添加一些 LCL 的使用说明文档。大家可以关注我的博客。
博客 http://luomingui.cnblogs.com
QQ交流群:由于暂时没有完整的帮助手册,所以新开通了一个 QQ 群,方便试用的朋友在里面进行交流。群号:34178394。

要使用LCLF进行应用程序开发,您需要安装Visual Studio 2012以上的版本(以下简称Visual Studio 2012+),从LCL 1.0开始,需要Micrsoft.NET Framework 4.5的支持,因此强烈建议使用Visual Studio 2012+进行开发。

使用NuGet来管理LCL的程序集引用的另一个好处是,使得今后LCL类库包的发布变得非常简单。

lclframework's People

Contributors

luomingui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lclframework's Issues

LCLFramework框架之Repository模式

Respository模式在示例中的实际目的小结一下

Repository模式是架构模式,在设计架构时,才有参考价值;
Repository模式主要是封装数据查询和存储逻辑;
Repository模式实际用途:更换、升级ORM 引擎,不影响业务逻辑;
Repository模式能提高测试效率,单元测试时,用Mock对象代替实际的数据库存取,可以成倍地提高测试用例运行速度。
Repository与Dal的区别

 Repository是DDD中的概念,强调Repository是受Domain驱动的,Repository中定义的功能要体现Domain的意图和约束,而Dal更纯粹的就是提  供数据访问的功能,并不严格受限于Business层。

 使用Repository,隐含着一种意图倾向,就是 Domain需要什么我才提供什么,不该提供的功能就不要提供,一切都是以Domain的需求为核心;而使用Dal,其意图倾向在于我Dal层能使用的数 据库访问操作提供给Business层,你Business要用哪个自己选。换一个Business也可以用我这个Dal,一切是以我Dal能提供什么操 作为核心。

LCLFramework框架之Repository模式设计

 LCLFramework框架之Repository模式设计主要是参考http://apworks.codeplex.com/ 框架而来的,目前我只是扩展了LCL.Repositories.EntityFramework仓库,对于个人来使用已经足够了。

ard_thumb[1]

LCLFramework框架之Repository模式设计代码

clipboard[1]

复制代码
public interface IRepository where TEntity : class, IEntity
{
IRepositoryContext Context { get; }
void Create(TEntity entity);
void Delete(TEntity entity);
void Update(TEntity entity);
IEnumerable Get(Expression<Func<TEntity, bool>> predicate);
IEnumerable GetAll(PagingInfo paging = null);
TEntity GetByKey(params object[] keyValues);
IEnumerable GetPage(Expression<Func<TEntity, bool>> predicate,PagingInfo paging);
}
public interface IRepositoryContext : IUnitOfWork, IDisposable
{
Guid ID { get; }
void RegisterNew(object obj);
void RegisterModified(object obj);
void RegisterDeleted(object obj);
}

public interface IUnitOfWork
{
bool DistributedTransactionSupported { get; }
bool Committed { get; }
void Commit();
void Rollback();
}
/*

职责:

1:定义一个“仓库”基类

2:与WCF交互,Repository类的红色部分是与WCF交互的代码。通过“数据门户”来决定是本地执行还是网络执行。

*/

public abstract partial class Repository : IRepository
where TEntity : class, IEntity
{
///

/// 是否声明本仓库为本地仓库(客户端只在客户端查询,服务端在服务端查询)
/// </summary>

public DataPortalLocation DataPortalLocation { get; protected set; }

private readonly IRepositoryContext context;
public Repository(IRepositoryContext context)
{
    this.context = context;

this.DataPortalLocation = DataPortalLocation.Dynamic;
}
public IRepositoryContext Context
{
get { return this.context; }
}
#region IRepositoryContext
#region CUD
protected abstract void DoAdd(TEntity entity);
protected abstract void DoRemove(TEntity entity);
protected abstract void DoUpdate(TEntity entity);
[Obfuscation]
public void Create(TEntity entity)
{
this.FetchList(entity, "DoAdd");
}
public void Delete(TEntity entity)
{
this.FetchList(entity, "DoRemove");
}
public void Update(TEntity entity)
{
this.FetchList(entity, "DoUpdate");
}
#endregion

#region Query
protected abstract IEnumerable<TEntity> DoGetAll(PagingInfo paging);
protected abstract IEnumerable<TEntity> DoGet(Expression<Func<TEntity, bool>> predicate);
protected abstract TEntity DoGetByKey(params object[] keyValues);
protected abstract IEnumerable<TEntity> DoGetPage(Expression<Func<TEntity, bool>> predicate, PagingInfo paging);
public IEnumerable<TEntity> Get(Expression<Func<TEntity, bool>> predicate)
{

var list = this.FetchList(predicate, "DoGet");
return list;
}
public IEnumerable GetAll(PagingInfo paging=null)
{
var list = this.FetchList(paging, "DoGetAll");
return list;
}
public TEntity GetByKey(params object[] keyValues)
{
var list = this.FetchFirst(keyValues, "GetByKey");
return list;
}
public IEnumerable GetPage(Expression<Func<TEntity, bool>> predicate,PagingInfo paging=null)
{
return this.FetchList(paging, "GetPage");
}
#endregion
#endregion

   #region 获取对象接口方法 

    protected TEntityList FetchListCast<TEntityList>(object criteria, string methodName) 

        where TEntityList : class, IEnumerable<TEntity> 

    { 

        return this.FetchList(criteria, methodName) as TEntityList; 

    } 

    protected TEntity FetchFirstAs(object criteria, string methodName) 

    { 

        return this.FetchFirst(criteria,methodName) as TEntity; 

    } 

    protected IEnumerable<TEntity> FetchList(object criteria, string methodName) 
    { 
        // 调用 " 数据门户 " 
        var list = DataPortalApi.Action(this.GetType(), methodName, criteria, this.DataPortalLocation) as IEnumerable<TEntity>; 
        return list; 
    } 

    protected TEntity FetchFirst(object criteria, string methodName) 

    { 

        var list = this.FetchList(criteria, methodName); 

        var last = list.DefaultIfEmpty<TEntity>() as TEntity; 

        return list.Count() > 0 ? last : null; 

    } 

    #endregion

}

public abstract class RepositoryContext :DisposableObject,IRepositoryContext

{

    #region Private Fields 

    private readonly Guid id = Guid.NewGuid(); 

    private readonly ThreadLocal<List<object>> localNewCollection = new ThreadLocal<List<object>>(() => new List<object>()); 

    private readonly ThreadLocal<List<object>> localModifiedCollection = new ThreadLocal<List<object>>(() => new List<object>()); 

    private readonly ThreadLocal<List<object>> localDeletedCollection = new ThreadLocal<List<object>>(() => new List<object>()); 

    private readonly ThreadLocal<bool> localCommitted = new ThreadLocal<bool>(() => true); 

    #endregion 

    #region Protected Properties 

    protected IEnumerable<object> NewCollection 

    { 

        get { return localNewCollection.Value; } 

    } 

    protected IEnumerable<object> ModifiedCollection 

    { 

        get { return localModifiedCollection.Value; } 

    } 

    protected IEnumerable<object> DeletedCollection 

    { 

        get { return localDeletedCollection.Value; } 

    } 

    #endregion 

    #region Protected Methods 

    protected void ClearRegistrations() 

    { 

        this.localNewCollection.Value.Clear(); 

        this.localModifiedCollection.Value.Clear(); 

        this.localDeletedCollection.Value.Clear(); 

    } 

    #endregion 

    #region IRepositoryContext Members 

    public Guid ID 

    { 

        get { return id; } 

    } 

    public virtual void RegisterNew(object obj) 

    { 

        localNewCollection.Value.Add(obj); 

        Committed = false; 

    } 

    public virtual void RegisterModified(object obj) 

    { 

        if (localDeletedCollection.Value.Contains(obj)) 

            throw new InvalidOperationException("The object cannot be registered as a modified object since it was marked as deleted."); 

        if (!localModifiedCollection.Value.Contains(obj) && !localNewCollection.Value.Contains(obj)) 

            localModifiedCollection.Value.Add(obj); 

        Committed = false; 

    } 

    public virtual void RegisterDeleted(object obj) 

    { 

        if (localNewCollection.Value.Contains(obj)) 

        { 

            if (localNewCollection.Value.Remove(obj)) 

                return; 

        } 

        bool removedFromModified = localModifiedCollection.Value.Remove(obj); 

        bool addedToDeleted = false; 

        if (!localDeletedCollection.Value.Contains(obj)) 

        { 

            localDeletedCollection.Value.Add(obj); 

            addedToDeleted = true; 

        } 

        localCommitted.Value = !(removedFromModified || addedToDeleted); 

    } 

    #endregion 

    #region IUnitOfWork Members 

    public virtual bool DistributedTransactionSupported 

    { 

        get { return false; } 

    } 

    public virtual bool Committed 

    { 

        get { return localCommitted.Value; } 

        protected set { localCommitted.Value = value; } 

    } 

    public abstract void Commit(); 

    public abstract void Rollback(); 

    #endregion 

    protected override void Dispose(bool disposing) 

    { 

        if (disposing) 

        { 

            this.localCommitted.Dispose(); 

            this.localDeletedCollection.Dispose(); 

            this.localModifiedCollection.Dispose(); 

            this.localNewCollection.Dispose(); 

        } 
    } 

}
复制代码

LCLFramework框架之Repository扩展

clipboard[2]

复制代码
public class EntityFrameworkRepository : Repository
where TEntity : class, IEntity
{
private readonly IEntityFrameworkRepositoryContext efContext;
public EntityFrameworkRepository(IRepositoryContext context)
: base(context)
{
if (context is IEntityFrameworkRepositoryContext)
this.efContext = context as IEntityFrameworkRepositoryContext;
}
protected override void DoAdd(TEntity entity)
{
efContext.RegisterNew(entity);
}
protected override void DoRemove(TEntity entity)
{
efContext.RegisterDeleted(entity);
}
protected override void DoUpdate(TEntity entity)
{
efContext.RegisterModified(entity);
}
protected override IEnumerable DoGetAll(PagingInfo paging)
{
if (paging != null)
{
paging.TotalCount = efContext.Context.Set().Count();
return efContext.Context.Set().OrderBy(t => t.ID).Skip(paging.PageNumber - 1 * paging.PageSize).Take(paging.PageSize).ToList();
}
else
{
return efContext.Context.Set().ToList();
}
}
protected override IEnumerable DoGet(Expression<Func<TEntity, bool>> predicate)
{
return efContext.Context.Set().Where(predicate).ToList();
}
protected override TEntity DoGetByKey(params object[] keyValues)
{
return efContext.Context.Set().Find(keyValues);
}
protected override IEnumerable DoGetPage(Expression<Func<TEntity, bool>> predicate, PagingInfo paging = null)
{
if (paging != null)
{
paging.TotalCount = efContext.Context.Set().Count();
return efContext.Context.Set().OrderBy(predicate).Skip((paging.PageNumber - 1) * paging.PageSize).Take(paging.PageSize).ToList();
}
else
{
return efContext.Context.Set().OrderBy(predicate).ToList();
}
}
}
public interface IEntityFrameworkRepositoryContext : IRepositoryContext
{
DbContext Context { get; }
}
public class EntityFrameworkRepositoryContext : RepositoryContext, IEntityFrameworkRepositoryContext
{
#region Private Fields
private readonly DbContext efContext;
private readonly object sync = new object();
#endregion
#region Ctor
public EntityFrameworkRepositoryContext(DbContext efContext)
{
this.efContext = efContext;
}
#endregion
#region Protected Methods
protected override void Dispose(bool disposing)
{
if (disposing)
{
efContext.Dispose();
}
base.Dispose(disposing);
}
#endregion
#region IEntityFrameworkRepositoryContext Members
public DbContext Context
{
get { return this.efContext; }
}
#endregion
#region IRepositoryContext Members
public override void RegisterNew(object obj)
{
this.efContext.Entry(obj).State = System.Data.Entity.EntityState.Added;
Committed = false;
}
public override void RegisterModified(object obj)
{
this.efContext.Entry(obj).State = System.Data.Entity.EntityState.Modified;
Committed = false;
}
public override void RegisterDeleted(object obj)
{
this.efContext.Entry(obj).State = System.Data.Entity.EntityState.Deleted;
Committed = false;
}
#endregion
#region IUnitOfWork Members
public override bool DistributedTransactionSupported
{
get { return true; }
}
public override void Commit()
{
if (!Committed)
{
lock (sync)
{
efContext.SaveChanges();
}
Committed = true;
}
}
public override void Rollback()
{
Committed = false;
}
#endregion
}
复制代码
LCLFramework框架之Repository使用

复制代码
public class Village : DomainEntity
{
public string Name { get; set; }
}
public interface IVillageRepository : IRepository
{
//仓库扩展
List GetTest();
}
[Serializable]
[RepositoryFor(typeof(Village))]
public class VillageRepository : EntityFrameworkRepository, IVillageRepository
{
private readonly IRepositoryContext context;
public VillageRepository(IRepositoryContext context)
: base(context)
{
this.context = context;
}
//仓库扩展方法
public List GetTest()
{
return new List();
}
}
复制代码

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.