structuremap

Does MS PnP Unity Scan for Assemblies Like StructureMap?

旧城冷巷雨未停 提交于 2019-12-02 04:11:49
In Using StructureMap 2.5 to scan all assemblies in a folder , we can see that StructureMap uses AssembliesFromPath() to explicitly look for types to resolve. What is the equivalent of this in Microsoft Unity? Because Unity is such a generic term, searching for documents about this online is not that easy. Update: Unity has something called an Assembly Matching Rule but its description does not communicate to me that it scans folders . The Assembly Matching Rule is used for applying interception to classes constructed by Unity and not for container registration. Unity itself does not have any

StructureMap warns caution when injecting in Session - Why?

我是研究僧i 提交于 2019-12-01 21:21:10
问题 In the StructureMap documentation on life cycle they state that one scoping option is HttpSession and that it: "Caches the instances in the HttpContext.Session collection. Use with caution." I don't know what to be cautious of and my google-fu is failing me. The use-case we have is that we have some expensive web service calls we'd like to cache. Some of which are stateless but some of which are tied to a particular user. When are we bad, naughty people if we inject in Session scope? What do

How can I dispose every instance object in StructureMap's ObjectFactory?

风流意气都作罢 提交于 2019-12-01 21:13:19
I'm using StructureMap in my project and when the application finishes running I need to call the Dispose() method on all of the Singleton instances inside the ObjectFactory that implement IDisposable. I cannot find anyway to do it via the StructureMap API. Another thought I had was to get a reference to every instance and call it myself, but I cannot figure out how to loop through all of the instances. PS: You might be interested in the deterministic disposal by Autofac IoC container Autofac can guarantee that components are disposed of predictably. Stefan Moser I found the answer in another

StructureMap HowTo: Conditional Construction on Deep Object

。_饼干妹妹 提交于 2019-12-01 21:06:46
I'm having difficulty conditionally creating a dependency. Googling, I have yet to find a good example of using the BuildStack and Conditional Predicates. Here's what I'm doing in the Registry: //snip public SomeRegistry() { this.InstanceOf<IFoo>().Is.Conditional( c => { c.TheDefault.Is.ConstructedBy(() => new FooZ()); c.If( p => p.ParentType.IsAssignableFrom(typeof(IBar)) && p.BuildStack.Current.RequestedType.IsAssignableFrom(typeof(IDoStuffWithFooA))) .ThenIt.Is.ConstructedBy(() => new FooA()); c.If( p => p.ParentType.IsAssignableFrom(typeof(IBar)) && p.BuildStack.Current.RequestedType

StructureMap error when invalid controller

爱⌒轻易说出口 提交于 2019-12-01 19:02:58
I am using Structure map like the MVC storefront by Rob Conery does and I have an AdminController and so to get to it I just type: website/Admin/action however if I miss spell the controller name I get the error below: Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: key There error occurs on this line: Controller controller = ObjectFactory.GetInstance(controllerType) as Controller; Does anyone have any ideas on how I can handle this error or not allow it to happen at all and maybe just goto a 404 page?? Cheers in advance The problem is that if there is no

StructureMap warns caution when injecting in Session - Why?

主宰稳场 提交于 2019-12-01 19:01:01
In the StructureMap documentation on life cycle they state that one scoping option is HttpSession and that it: "Caches the instances in the HttpContext.Session collection. Use with caution." I don't know what to be cautious of and my google-fu is failing me. The use-case we have is that we have some expensive web service calls we'd like to cache. Some of which are stateless but some of which are tied to a particular user. When are we bad, naughty people if we inject in Session scope? What do we need to guard against? I'll describe the problems with this by using an extreme example, caching a

What do I do when ASP.NET 5 (vNext) can't redirect bindings?

我的梦境 提交于 2019-12-01 18:27:13
I am just getting my feet wet with MVC 6. I installed VS 2015 and with the default ASP.NET 5 preview MVC Web Application template everything runs fine under local IIS. I then tried to switch out the Default DI container with StructureMap following these instructions exactly (note it is a very recent article). The only thing is I had to figure out the namespaces to import myself (since the author neglected to include them) and this is what I included. I put the StructureMapRegistration class and all related classes into a single file, and here are the usings. using Microsoft.Framework

StructureMap: Choose concrete type of nested dependency

╄→гoц情女王★ 提交于 2019-12-01 17:57:46
Calculators: public interface ICalculator { int Calculate(int a, int b); } public class Calculator : ICalculator { private readonly ICalculatorStrategy _calculatorStrategy; public Calculator(ICalculatorStrategy calculatorStrategy) { _calculatorStrategy = calculatorStrategy; } public int Calculate(int a, int b) { return _calculatorStrategy.Calculate(a, b); } } Calculator stragies: public interface ICalculatorStrategy { int Calculate(int a, int b); } public class AdditionCalculator : ICalculatorStrategy { public int Calculate(int a, int b) { return a + b; } } public class MultiplyCalculator :

NLog: Dependency Injection for custom Targets

两盒软妹~` 提交于 2019-12-01 17:25:40
问题 I am a user of NLog and I am creating my own custom target. This target will use some repositories (using NHibernate) to persist log entries. Is it possible to inject the required constructor dependencies of custom targets using any IoC framework, preferably StructureMap? Regards, J 回答1: I want to provide some context for people, since I was confused at first by your answer JC. public Program { // // Static constructor // static Program() { // Set up Ninject var kernel = new StandardKernel();

Getting Fluent NHibernate To Build Database tables

丶灬走出姿态 提交于 2019-12-01 14:00:36
I am building an app with ASP.NET MVC2, Fluent NHibernate, StructureMap, and PostgreSQL. I am a total newbie when it comes to Fluent NHibernate. I got a setup going from a couple different sources but when I build and run my app it doesnt create the database tables for the database in my connection string. I have code in a few different files so Im not sure which code I need to post of if I should post all of it. If there is one key to check for please let me know or let me know to post all the code. Thanks! You can use the SchemaExport class from NHibernate Core to export your schema to a