跨平台(Xamarin)应用中使用哪个IoC容器? [英] Which IoC continer to use in cross-platform (Xamarin) applications?

查看:68
本文介绍了跨平台(Xamarin)应用中使用哪个IoC容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在ASP.NET中为Windows,OSX,iOS,Windows Mobile,Android和Web构建跨平台应用程序。对于每个客户,我都使用C#(我在使用Xamarin)。单个VS解决方案中的所有内容。我的核心代码(域)位于类库(便携式)中,因此可以在每个UI(客户端)中使用。

I'm building a cross-platform application for Windows, OSX, iOS, Windows Mobile, Android and web in ASP.NET. For every client I use C# (I'm using Xamarin). Everything in single VS solution. My core code (domain) is in Class Library (portable), so it can be used in every UI (Client).

我想要在该项目中使用IoC容器,这就是我的问题:
我不知道我会选择的IoC是否适用于每个客户端。我知道例如 Ninject 在便携式类库中不起作用-该项目有 Ninject.Portable 。这让我开始思考,我选择的IoC可能无法在我的一位客户中使用,这很不好。

I want to use IoC container in that project and here is my problem: I don't know whether IoC that I'll pick, will work in every Client. I know that for example Ninject doesn't work in portable Class Library - there is Ninject.Portable for such project. That made me thinking, it's possible that IoC which I will pick will not work in one of my Clients which will be bad.

所以,我的问题是:哪些IoC容器可用于可移植类库以及Visual Studio 2015中制作的每个客户端(UI)中? >

So, my question is: Which IoC containers can be used in portable class libraries and in every client (UI) made in Visual Studio 2015?

我对简单注入器感兴趣,但是现在我有这些疑问。

I was interested in Simple Injector, but now I have these doubts.

推荐答案

我在IoC容器和与Xamarin一起使用的容器的插件上编写了一个小的抽象层。它们在NuGet上可用:

I have written a small abstraction layer on IoC containers and plugins for containers that work with Xamarin. They are available on NuGet:

https:// www .nu​​get.org / packages?q = xlabs.ioc

经过测试的容器(单元测试在GitHub中):


  • Autofac

  • Ninject

  • SimpleInjector

  • TinyIOC

  • Unity

  • Autofac
  • Ninject
  • SimpleInjector
  • TinyIOC
  • Unity

Matt Whetton写了出色的使用方法指南

Matt Whetton has written an excellent guide on how to use them.

这篇关于跨平台(Xamarin)应用中使用哪个IoC容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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