这些类/方法应该去哪里?

发布于 2024-10-13 10:34:11 字数 892 浏览 4 评论 0原文

我有一个像这样的

WebUI 项目的结构 - 控制器、视图 框架项目 - 存储库、服务层和域

所以现在我有 3 个方法/类

  1. Open Id/Open auth

起初我以为我会将所有逻辑放在框架项目的服务层中(准备请求、检查响应等)将在这一层)。

所以现在我正在使用 dotnetopenauth 库,因为我需要在控制器中使用 AsActionResult 方法(我从服务层返回“OutgoingWebResponse”,因为我不想在服务层中使用任何 MVC),

这让我开始思考决定不在我的服务层中使用任何 MVC。据我所知,包含业务逻辑的服务层不应具有任何依赖项(例如 MVC 引用),因为如果您使用 Windows Phone 应用程序,则不应使用 MVC 内容。

您的业​​务层应该可以在任何应用程序中即插即用。

所以现在我不确定是否应该将我为 openId 编写的内容移动到我的 mvc 项目中的 models 文件夹中,只是出于上述原因。因为如果我确实使用 Windows Phone 应用程序或表单应用程序,我将不会使用 dotnetopenauth,因为我认为这些类型的应用程序不支持它。

  1. 我的第二个是表单身份验证。同样的原因与上面几乎相同。这是否应该在我的模型文件夹中作为本地服务/存储库层(即在同一项目文件中)。

  2. 我正在使用 nhibernate、Fluent nhiberate 和 ninject。我的仓库都在我的框架项目中。所以我当然有所有的参考资料。但由于我使用 ninject 进行 ioc,所以我的 webui 项目中也有所有参考资料。

我不知道是否可以更改此内容以从我的 webui 中删除这些引用。我想不,因为他们我不能在我的 webui 中拥有我的 ioc,我认为它应该去。

I have a structure like this

WebUI project - controllers, views
Framework project- repositories,service layer and domain

So now I have 3 methods/classes

  1. Open Id/Open auth

At first I thought I would put all my logic in a service layer in my framework project(preparing the request, checking the response and etc would be in this layer).

So now I am using the dotnetopenauth library and because I need to use the AsActionResult method in my controller(I return "OutgoingWebResponse" from my service layer as I don't want anything MVC in my service layers)

It got me to thinking when I decided not to have anything MVC in my service layer. As what I read is that your service layer that contains your business logic should not have any dependencies like MVC references because if you go to a windows phone application you should not be using MVC stuff.

Your business layer should be sort of plug and play into any application.

So now I am not sure if I should move what I wrote for openId into my models folder in my mvc projectjust for the reasons above. Since if I do go to a windows phone application or forms application I won't be using dotnetopenauth since I don't think it's supported in these types of applications.

  1. My second one is with forms authentication. Again pretty much same reasons as above. Should this go as well in my models folder as a local service/repo layer(ie in the same project file).

  2. I am using nhibernate, fluent nhiberate and ninject. My repos are all in my framework project. So I have of course all the references in there. But since I am using ninject for ioc I have all the references in my webui project as well.

I have no clue if this one could be changed to get rid of these references from my webui. I am thinking no because they I can't have my ioc in my webui where I think it should go.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_畞蕅 2024-10-20 10:34:11

作为一般经验法则,您不应根据不存在的需求编写代码(将应用程序移植到 Windows Phone)。

通常,您会在服务层中将其抽象出来,但是 OAuth 或 Facebook 集成会带来问题,因为它依赖于 http 并且能够访问身份验证站点。

因为“所有抽象都有漏洞”而遇到的问题是你的服务层无论您将其放置在何处,openauth 注册过程都会以某种方式损坏。有关用户注册和登录的详细信息(例如他们的 openid url 是什么)最终将存储在您的数据库中。由于 openauth 的本质,您的 service/repo/db/model/mvc/viewmodel/controllers 类都会知道 openauth 是什么。

好处是这些基于浏览器的身份验证策略可以存在于 Windows Form、WPF 或 Silverlight 应用程序中。您只需在应用程序内打开浏览器,而不是使用 MVC 进行本机重定向。

因此,我建议将 dotnetopen 身份验证注册代码放置在服务层内,并实际抽象出重定向和回调过程如何发生。

就像:

public interface IOpenAuthRedirect
{
      public void Redirect( url )
      public void ParseCallback( url )
}


public class MVCOpenAuthRedirect
{
     public void Redirect(url)
     {
        HttpContext.Current.Response.Redirect(url);
     }
}

public class SilverlightOpenAuthRedirect
{
    public void RedirectUrl( url )
    {
        SomeBrowserControl.IForgetTheCallToRedirect( url );
    }   

}

现在不同的实现细节很灵活,您可以轻松过渡到 MVC 之外的另一个平台。

As a general rule of thumb you shouldn't write code against requirements that don't exist ( porting the app to a windows phone ) .

Normally you'd abstract this out in your service layer however OAuth or Facebook integration poses a problem because of its reliance on http and being able to visit the authenticating site.

The problem you'll run into because "all abstractions are leaky" is that your service layer will be corrupted somehow by the openauth registration process regardless of where you place it. Details about user registration and login such as what their openid url is will end up in your database. You're service/repo/db/model/mvc/viewmodel/controllers classes are all going to know what openauth is because of its nature.

The good thing is these browser based authentication strategies can live in a Windows Form, WPF or Silverlight application. You simply open a browser inside the application instead of redirecting natively with MVC.

So what I'd recommend is placing your dotnetopen auth registration code inside of your service layer and actually abstracting out how the redirection and callback process happens.

Something like:

public interface IOpenAuthRedirect
{
      public void Redirect( url )
      public void ParseCallback( url )
}


public class MVCOpenAuthRedirect
{
     public void Redirect(url)
     {
        HttpContext.Current.Response.Redirect(url);
     }
}

public class SilverlightOpenAuthRedirect
{
    public void RedirectUrl( url )
    {
        SomeBrowserControl.IForgetTheCallToRedirect( url );
    }   

}

Now the different implementation details are flexible and you can easily transition to another platform besides MVC.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文