下面的代码可以在DryIoc 2.x中运行。我刚刚更新到了4.x。代码不再工作(参见下面的异常)。看起来,4.x将"ScopedTo“数据视为非独占数据,而在2.x中,它们是作用域独占的--它们不适用于其他作用域。现在我如何获得2.x的行为?异常列出了几种补救措施,但是哪种补救措施与2.x行为相匹配? using System;
using DryIoc;
namespace TestDryIoc
{
public interface IDep {}
public interface IOwner
{
IDep Dep { get; }
看看 for DryIoc,这些例子似乎显示了我所需要的相反的东西,我想知道是否有可能发生相反的情况?
Wiki (部分示例)
public interface X {}
public interface Y {}
public class A : X, Y {}
public class B : X, IDisposable {}
// Registers X, Y and A itself with A implementation
container.RegisterMany<A>();
...
我想做以下几件事
container.RegisterMany<
在我的Xamarin.Forms应用程序中,我正面临以下错误。
Interpreter.TryInterpretAndUnwrapContainerException (DryIoc.IResolverContext r, FastExpressionCompiler.LightExpression.Expression expr, System.Boolean useFec, System.Object& result)
System.NullReferenceException: Object reference not set to an instance of an objec
我正在尝试使用DryIoc Mef库来扫描具有导出属性的所有程序集 我看到了关于Mef与DryIoc的链接 我将方法更改为RegisterExports,但是没有注入IGreeter属性。如果我自己注册每一个,它就能工作(Foo/Greeter)。 using DryIoc;
using DryIoc.MefAttributedModel;
using System;
using DryIocAttributes;
namespace ConsoleApp3
{
class Program
{
public static IContainer C;
static void
我决定在我的C#应用程序中更改IOC。它从Unity移动到Dryloc。我的问题是我不知道如何在容器中注册对象。
在Unity中,它是这样工作的:
AppConfiguration config = new AppConfiguration(){...}
var container = new UnityContainer();
container.Register(config);
但是如何在Dryloc中做到这一点?
更新1:
我试过这样的代码:
AppConfiguration config = new AppConfiguration(){...}
var container
我的应用程序在最后一行中出错:
var ioc= new DryIoc.Container();
var Task = DryIoc.Resolver.Resolve<XXX>(ioc);
收到的错误:
无法解决XXX。没有找到服务注册和Rules.FallbackContainers数:0和Rules.UnknownServiceResolvers数:0
我的代码:
class XXX: AAA
{ ...
}
标题可能具有误导性,但基本上我希望DryIoc.Container解析一个特定的实现,该接口的类型(实现接口的类的类型)在运行时(相同接口的多个实现<code>E 210</code>被注册)。我不能使用serviceKey来识别实现,因为解析实现的代码预期会执行如下操作:container.Resolve<IService>(*** here specify the runtime type of the implementation ***)来获得我们想要的实现(实现的类型是通过我们在运行时读取的配置获得的)。
using System;
我正在尝试为DryIoc创建一个(v2.0预览版)。通常情况下,大多数事情看起来都很简单,但是DryIoc似乎并不支持南希依赖的东西之一。
内置的tinyioc容器在面对一个具有两个“相同长度”构造函数的类型(即相同数量的参数,但它们的类型不同)时,将解析其具有完整类型注册集的类型。
在运行我的引导程序时,在RegisterTypes方法中抛出一个异常:
Additional information: Unspecified how to select single constructor for implementation type Nancy.ViewEngines.FileSystem
如何检查以前在DryIoC中当前范围内创建的服务?
如果没有使用dryioc创建服务,我希望阻止创建服务。
在本例中,我需要一个类似于IsResolved的函数:
container.Register<S>();
if (container.IsResolved<S>()==true){ //always false
//Do any thing
}
var s = container.Resolve<S>();
if (container.IsResolved<S>()==true){ //
我有一个Xamarin.Forms应用程序,它使用Prism和DryIoC作为容器。我有一个值转换器,在这里我需要使用我通过IContainerRegistry注册的服务。
containerRegistry.RegisterSingleton<IUserService, UserService>();
既然IValueConverter是由XAML而不是DryIoC构造的,那么我如何解决这个依赖关系,而不需要诉诸构造函数注入呢?我可以在棱镜/DryIoC中使用服务定位器吗?如果是,怎么做?
以下是值转换器代码:
public class MyValueConverter : IV
我很难使用DryIoc将构造函数注入到使用Prism和Xamarin的ViewModel中。我正在使用Nuget软件包Prism.DryIoc.Forms。
在我的项目中,AuthenticatePage.xaml.g.cs中出现了以下错误
Unable to resolve Object {RequiredServiceType=Project.ViewModels.AuthenticatePageViewModel} with 1 arg(s)
in wrapper Func<Xamarin.Forms.Page, Object> {RequiredServiceType=P
我搜索了一个简单的示例,说明如何将DryIoc容器配置为将依赖项简单地注入属性,就像它注入构造函数args一样。
鉴于下面的工作示例..。
货柜登记:
public static void Register(HttpConfiguration config)
{
var c = new Container().WithWebApi(config);
c.Register<IWidgetService, WidgetService>(Reuse.Singleton);
c.Register<IWidgetRepo
我正在使用DryIOC.WebAPI来解析我的APIControllers。
因此,WebAPI Config是:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefa