Which IoC continer to use in cross-platform (Xamar

2020-06-03 06:04发布

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).

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.

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.

2条回答
混吃等死
2楼-- · 2020-06-03 06:20

There is an IoC container which works with Xamarin called SystemDot. It's on nuget.

查看更多
手持菜刀,她持情操
3楼-- · 2020-06-03 06:39

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.nuget.org/packages?q=xlabs.ioc

Tested containers (unit tests are in GitHub):

  • Autofac
  • Ninject
  • SimpleInjector
  • TinyIOC
  • Unity

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

查看更多
登录 后发表回答