// Enrich with is enriching more than i want
public intefrace ICommand {
void Execute();
}
// classes
public class A : ICommand {}
public class B : ICommand {}
public class MultiCommand : ICommand {
public MultiCommand(ICommand[] commands) {}
}
// -- decorators
public DecoratorOne : ICommand {
public DecoratorOne(Icommand toDecorate) {}
}
public DecoratorTwo : ICommand {
public DecoratorOne(Icommand toDecorate) {}
}
// what i tried
ForREquesedType<ICommand>()
.TheDefaultIsConcreteType<A>
.EnrichWith(x => new DecoratorOne(x)
.EnrichWith(y => new DecoratorTwo(y)
.CacheBy(InstanceScope.Singleton);
InstanceOf<ICommand>() …Run Code Online (Sandbox Code Playgroud) 你好.我试图解决一个显然并不罕见的问题,我不知道如何找到这个问题是如何解决的.当我通过IIS在我的机器上运行StructureMap时,我得到一个异常,它看起来像这样:
**Description**: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
**Exception Details**: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Run Code Online (Sandbox Code Playgroud)
这个问题已经出现在SO(/sf/ask/54926651/),这篇博客文章的评论和大约一年前的结构图邮件列表上.
我的问题不是在外部托管环境中运行它.我甚至不能让它在我自己的盒子上运行(IIS 7.5,Win7 RC,.NET 3.5).我试图将站点配置为使用自定义策略文件,并且FileIOPermission被标记为具有不受限制的访问权限...没有骰子.如果有人有一些提示或链接,将不胜感激.
更新 因此,这是解决问题的最佳方法,但是在深入探讨Joshua所提到的内容之后,我需要做的就是让它工作:StructureMap,Code Access Security和一个糟糕的解决方案一个问题.将会有一个更好的解决方案.
假设我在界面中定义了一个事件.
然后我有许多实现该接口的类.
这些类的创建由StructureMap管理.
现在说我有一个委托,我想用作所有这些新创建的实例的事件处理程序.
有没有办法告诉StructureMap将事件处理程序附加到它创建的对象?
(注意:我目前的解决方案是创建一个Notifier类并通过构造函数传递它,这可以完成工作,但我很好奇我是否可以消除中间人.)
我目前正在使用StructureMap使用以下代码注入NHibernate ISessions的实例:
ObjectFactory.Initialize(x =>
{
x.ForRequestedType<ISession>()
.CacheBy(InstanceScope.PerRequest)
.TheDefault.Is.ConstructedBy(y => NHibernateSessionManager.Instance.GetSession());
});
Run Code Online (Sandbox Code Playgroud)
我假设CacheBy(InstanceScope.PerRequest)将正确处理它创建的ISession,但我想确定.测试这个的最简单方法是什么?
我是NLog的用户,我正在创建自己的自定义目标.此目标将使用一些存储库(使用NHibernate)来持久保存日志条目.
是否可以使用任何IoC框架(最好是StructureMap)注入自定义目标所需的构造函数依赖项?
问候,
Ĵ
我在我的本地计算机上的一个ASP.NET 4.5 MVC应用程序中收到此错误.使用ASP.NET 4.5设置其他应用程序并使用StructureMap可以正常工作.

任何帮助/解决方案都将受到高度赞赏.导致这种情况的代码行是:
using StructureMap;
using StructureMap.Graph;
namespace Management.Web.DependencyResolution
{
public static class IoC
{
public static IContainer Initialize()
{
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.Assembly("Management.Core");
scan.Assembly("Management.DAL");
scan.Assembly("Management.BusinessServices");
scan.Assembly("Management.Infrastructure");
});
x.For<INavigationService>().Use<NavigationService>();
});
return ObjectFactory.Container;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我试图从我的视图中调用一个Action @Html.Action("ActionName","controllerName").但我的页面无法加载以下错误:
控制器'Ki_PathwaysWeb.Areas.LearningManager.Controllers.ActionController'的单个实例不能用于处理多个请求.如果正在使用自定义控制器工厂,请确保它为每个请求创建控制器的新实例.
我正在使用结构图进行依赖注入.请帮帮我,我错过了什么.
structuremap dependency-injection inversion-of-control asp.net-mvc-5
如何使用DecorateAllWithDynamicProxy进行装饰所有实例都实现了一个接口?
例如:
public class ApplicationServiceInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
// ...
invocation.Proceed();
// ...
}
}
public class ApplicationServiceConvention : IRegistrationConvention
{
public void Process(Type type, Registry registry)
{
if (type.CanBeCastTo<IApplicationService>() && type.IsInterface)
{
var proxyGenerator = new ProxyGenerator();
// ??? how to use proxyGenerator??
// ???
registry.For(type).DecorateAllWith(???); // How to use DecorateAllWith DynamicProxy ...??
}
}
}
Run Code Online (Sandbox Code Playgroud)
我可以使用(例如)装饰一些具体类型的接口:
var proxyGenerator = new ProxyGenerator();
registry.For<IApplicationService>().Use<BaseAppService>().DecorateWith(service => proxyGenerator.CreateInterfaceProxyWithTargetInterface(....))
Run Code Online (Sandbox Code Playgroud)
但是无法使用DecorateAll来做到这一点.
要打电话registry.For<>().Use<>().DecorateWith()我必须这样做:
if (type.CanBeCastTo<IApplicationService>() && …Run Code Online (Sandbox Code Playgroud) 在从StructureMap 2.6.4升级到StructureMap 3.1.6之后,我们在嵌套容器中的通用接口的注册停止工作,我找不到它们不再工作的原因.
这是我得到的错误
StructureMap.StructureMapConfigurationException:没有注册默认实例,无法自动确定类型'ITest <ExtendClass>'
以下是演示此问题的示例:
public class StructureMapContainerTests
{
[Test]
public void GlobalContainer()
{
var container = new Container();
container.Configure(x => x.For(typeof(ITest<>)).Use(typeof(Test<>)));
var impl = container.GetInstance<ITest<ExtendClass>>();
Debug.WriteLine(impl.Temp()); //Works
}
[Test]
public void NestedContainer()
{
var container = new Container();
var nestedContainer = container.GetNestedContainer();
nestedContainer.Configure(x => x.For(typeof(ITest<>)).Use(typeof(Test<>)));
var impl = nestedContainer.GetInstance<ITest<ExtendClass>>();
Debug.WriteLine(impl.Temp()); //Doesn't work
}
}
public interface ITest<T> where T : BaseClass
{
string Temp();
}
public class Test<T> : ITest<T> where T : ExtendClass
{
public string …Run Code Online (Sandbox Code Playgroud) 我有Asp.Net MVC应用程序,我使用了structuremap,我使用自定义ThrottleAttribute ActionFilter.遵循asp.net mvc中的速率限制
public enum TimeUnit
{
Minute = 60,
Hour = 3600,
Day = 86400
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class ThrottleAttribute : ActionFilterAttribute
{
public TimeUnit Time { get; set; }
public int Count { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var seconds = Convert.ToInt32(Time);
var key = string.Join(
"-",
seconds,
filterContext.HttpContext.Request.HttpMethod,
filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
filterContext.ActionDescriptor.ActionName,
filterContext.HttpContext.Request.UserHostAddress
);
// increment the cache value
var cnt = 1;
if (HttpRuntime.Cache[key] != null)
{
cnt = …Run Code Online (Sandbox Code Playgroud) structuremap ×10
c# ×5
.net ×3
.net-3.5 ×1
asp.net ×1
asp.net-mvc ×1
generics ×1
iis ×1
nhibernate ×1
nlog ×1