使用asp.net身份时如何分离模型库 [英] how to separate model library when using asp.net identity

查看:63
本文介绍了使用asp.net身份时如何分离模型库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建具有分层体系结构的应用程序.我有单独的

I want to create application with layered architecture. I have separate

  • 仅具有模型类的模型项目
  • 负责CodeFirst配置,迁移等的数据项目,
  • 负责业务逻辑并使用EF将数据保存在数据库中的服务项目
  • Dto项目,其中包含在Web应用程序和服务之间使用的类
  • 带有asp.net mvc应用程序的Web项目.

我的目标是分离这些项目,以便Web项目对模型和数据一无所知-它仅使用Dto类消耗Service,因此Web项目应仅引用Service和Dto.在我配置了Asp.Net Identity之前,一切都非常好-为了配置授权,我不得不引用我想避免的数据和模型项目.是否有可能实现我的目标,以及(如果可以的话)如何实现目标.

My goal was to separate these projects so that Web project knows nothing about Model and Data - it just consumes Service using Dto classes, so the Web project should just reference Service and Dto. Everything was great until I configured Asp.Net Identity - in order to configure authorization I had to reference Data and Model project which I had wanted to avoid. Is it possible to achieve my goal, and (if so) how to do it.

我的第二个问题是:从关注点分离的角度来看,我的设计还可以吗?

My second question is: is my desing ok from the separation of concerns point of view?

推荐答案

我可以将所有ASP.NET Identity内容分离到它自己的项目中,该项目同时包含EF数据访问和身份模型.可以将其视为是将关注点更局部地或按主题而不是按功能分开.

I might separate all the ASP.NET Identity things into its own project housing both the EF data access and identity models. Think of it as separating the concerns more topically or by the subject matter, rather than by function.

因此您的Web应用程序随后将引用Service,Dto和Identity-,每个人似乎都有自己的世界.

So your web app would then reference Service, Dto, and Identity- and everybody seems to have their own corner of the world.

imo的目标不一定是通过类似的功能来划分代码,而是消除不需要的依赖,并将领域知识隐藏(或保护)在孤立且权威的模块中.

The goal, imo, is not necessarily to divvy up code by similar functionality, but to eliminate dependencies where none are needed, and to hide (or rather protect) domain knowledge into isolated and authoritative blocks.

是的,您的设计基本上是牢固的,并且通常可以很好地工作.

Yes, your design is basically solid and generally works well.

这篇关于使用asp.net身份时如何分离模型库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆