structuremap

Operation could destabilize the runtime in StructureMap

荒凉一梦 提交于 2019-11-28 10:23:59
I am getting this error in one of my ASP.NET 4.5 MVC application on my local machine. Other applications setup with ASP.NET 4.5 and using StructureMap work fine. Any help/solution on this would be highly appreciated. The line of code that causes this is: 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

WebAPI + APIController with structureMap

♀尐吖头ヾ 提交于 2019-11-28 07:27:36
Im trying to use StructureMap to initialize my ValuesController that derivate from ApiController but i'm getting an exception that says: The IControllerFactory '...CustomControllerFactory' did not return a controller for the name 'api'. Here is the code.. public class CustomControllerFactory : DefaultControllerFactory { protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) { if (controllerType == null) return null; return (Controller)ConcretizationsManager.GetInstance(controllerType); } } basically ConcretizationsManager is a wrapper of

StructureMap Exception Code: 202 No Default Instance defined for PluginFamily

浪子不回头ぞ 提交于 2019-11-28 06:58:14
问题 I am new to StructureMap. I have downloaded and am using version 2.6.1.0. I keep getting the below error: StructureMap Exception Code: 202 No Default Instance defined for PluginFamily Company.ProjectCore.Core.IConfiguration, Company.ProjectCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null My Global.asax.cs looks like: protected void Application_Start(object sender, EventArgs e) { var container = new Container(x => { x.For<ICache>().Use<Cache>(); x.For<IEmailService>().Use

Ways of keeping configuration code out of logic code using Dependency Injection

两盒软妹~` 提交于 2019-11-28 04:40:32
How can keep all the configuration file code out of my logic code using Settings (ApplicationSettingsBase) and Dependency Injection? With configuration I mean a customer specific configuration file. Do I really have to inject a configuration class everytime I need it or is there another pattern? It would be great to get some sample code! Samples: Static Configuration: public static class StaticConfiguration { public static bool ShouldApplySpecialLogic { get; set; } public static string SupportedFileMask { get; set; } } public class ConsumerOfStaticConfiguration { public void Process() { if

NHibernate and Structure Map

我只是一个虾纸丫 提交于 2019-11-28 04:25:46
So I really like working with NHibernate but always used Spring.Net with it. I recently came across StructureMap by Jeremy Miller and really like it better than Spring.Net. On his StructureMap site he promises an example on how to use NHibernate and StructureMap together. Unfortunately he has not had time to do it (or I can't find it). So does anyone have an example on how to handle the NHibernate Session with StructureMap? So, I apologize that we did not get the NHibernate with StructureMap example done earlier. Eventually, I would like to publish it in the StructureMap documentation, but I

What is the difference between HybridHttpOrThreadLocalScoped & HttpContextScoped

…衆ロ難τιáo~ 提交于 2019-11-27 23:27:57
问题 Simply, what is the difference between HybridHttpOrThreadLocalScoped & HttpContextScoped? 回答1: HttpContext always uses HttpContext (and fails if not running within a web request). HybridHttpOrThreadLocalScoped uses the HttpContext when available - if not, it falls back to caching per thread. 来源: https://stackoverflow.com/questions/3014061/what-is-the-difference-between-hybridhttporthreadlocalscoped-httpcontextscoped

IQueryable Repository with StructureMap (IoC) - How do i Implement IDisposable?

人走茶凉 提交于 2019-11-27 18:55:20
问题 If i have the following Repository: public IQueryable<User> Users() { var db = new SqlDataContext(); return db.Users; } I understand that the connection is opened only when the query is fired: public class ServiceLayer { public IRepository repo; public ServiceLayer(IRepository injectedRepo) { this.repo = injectedRepo; } public List<User> GetUsers() { return repo.Users().ToList(); // connection opened, query fired, connection closed. (or is it??) } } If this is the case, do i still need to

How to register All types of an interface and get instance of them in unity?

匆匆过客 提交于 2019-11-27 18:14:37
问题 How unity can get all instances of an interface and then access them? Code pieces are taken from here : Fail-Tracker In StrcutureMap its possible to register all types of an interface from an assembly and then access them like following: public class TaskRegistry : Registry { public TaskRegistry() { Scan(scan => { scan.AssembliesFromApplicationBaseDirectory( a => a.FullName.StartsWith("FailTracker")); scan.AddAllTypesOf<IRunAtInit>(); scan.AddAllTypesOf<IRunAtStartup>(); scan.AddAllTypesOf

Configuring dependency injection with ASP.NET Web API 2.1

筅森魡賤 提交于 2019-11-27 18:10:19
I'm creating an ASP.NET Web API 2.1 site and as I want to inject dependencies directly into the controllers, I've created my own implementation of IDependencyResolver so that StructureMap will handle that for me. public class StructureMapDependencyResolver : IDependencyResolver { public IDependencyScope BeginScope() { return this; } public object GetService(Type serviceType) { return ObjectFactory.GetInstance(serviceType); } public IEnumerable<object> GetServices(Type serviceType) { return ObjectFactory.GetAllInstances(serviceType).Cast<object>(); } public void Dispose() { } } I've then told

WebActivator.PreApplicationStartMethod does not work

荒凉一梦 提交于 2019-11-27 16:14:14
问题 [assembly: WebActivator.PreApplicationStartMethod(typeof(MyApp.App_Start.StructureMapMvc), "Start")] namespace MyApp.App_Start { public static class StructureMapMvc { public static void Start() { var container = IoC.Initialize(); DependencyResolver.SetResolver(new SmDependencyResolver(container)); } } } Here is my code that is supposed to run before Application_start in global.asax. I was upgrading my web project from mvc 3 to mvc 4. So, In that process, I made a mistake in namespace. This