structuremap

StructureMap Exception Code: 202 No Default Instance defined for PluginFamily

我怕爱的太早我们不能终老 提交于 2019-11-29 09:08:12
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<EmailService>(); x.For<IUserSession>().Use<UserSession>(); x.For<IRedirector>().Use<Redirector>(); x.For

Strange behaviour with StructureMap / ASP.MVC / Visual Studio / LinqToSql

强颜欢笑 提交于 2019-11-29 07:42:52
I have been using the new MVC framework with StructureMap recently and have had good results overall, however, I keep running into a very strange error that I cannot understand or work out how to resolve. This is my architecture: DBContext - linqToSql data context. IRepository - contract defining data methods. IService - contract defining service methods. Controllers - two in this example. I therefore have: public class Repo : IRepository { public Repo(DBContext db) { ..... } } public class Service : IService { public Service(IRepository repo) { ..... } } public class ControllerOne :

How to map same interface to different ConcreteClasses with StructureMap?

最后都变了- 提交于 2019-11-29 07:21:55
When Controller1 is being created, I want that IService will be mapped to ConcreteService1 and IPageService to ConcretePageService1 And when Controller2 is created, I want that IService will be mapped to ConcreteService2 and IPageService to ConcretePageService2 How I can initialize ObjectFactory so that the above will work? Mean while I initialezed ObjectFactory this way: ObjectFactory.Initialize(x => { x.For<IService>().Use<ConcreteService1>(); x.For<IPageService>().Use<ConcretePageService1>(); }); But this ALWAYS maps ConcreteService1 to IService and ConcretePageService1 to IPageService

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

一笑奈何 提交于 2019-11-29 04:48:44
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 make my Repository implement IDisposable? The Visual Studio Code Metrics certainly think i should. I'm

IoC, Dll References, and Assembly Scanning

女生的网名这么多〃 提交于 2019-11-29 02:57:39
问题 Although this question is related to StructureMap, my general question is: When wiring up components with an IoC container in code (as opposed to configuring via xml ) do you generally need explicit project/build references to all assemblies? Why the separate assemblies? Because: "Abstract classes residing in a separate assembly from their concrete implementations are a great way to achieve such separation." - Framework Design Guidelines p.91 Example: Let's say I have PersonBase.dll and Bob

WebActivator.PreApplicationStartMethod does not work

核能气质少年 提交于 2019-11-29 01:48:01
[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 was working before i corrected my namespace. It no longer works now. I reset iis/flushed dns/ rebuilt

Custom Controller Factory, Dependency Injection / Structuremap problems with ASP.NET MVC

早过忘川 提交于 2019-11-28 22:20:08
问题 I recently tried to implement dependency injection using StructureMap. I managed to follow the example all the way but I'm encountering a thrown exception every time I try to run the application. Here's some code snippets from my controller factory. public class StructureMapControllerFactory : DefaultControllerFactory { protected override IController GetControllerInstance(Type controllerType) { if (controllerType == null) throw new ArgumentNullException("controllerType"); return ObjectFactory

How do I get StructureMap working with an AngularJs / MVC5 and WebApi2 web project

ε祈祈猫儿з 提交于 2019-11-28 21:52:01
So I have an AngularJs/MVC project with normal Controllers and decided to move more to an SPA app and add WebApi2 to pass data back to my UI instead of using MVC. In my Global.asax I had the following for my MVC project: DependencyResolver.SetResolver(new StructureMapDependencyResolver(container)); My WebApiController has a constructor with an IRepository to talk to the database and get some entities back. When my AngularJS web app makes a call to the controller the break points never hit and I'm getting server 500 errors returned with very little information. Public class MyController :

Using structuremap with log4net wrapper

时间秒杀一切 提交于 2019-11-28 18:02:33
I have the following interface: public interface ILogger { void Debug(string message, params object[] values); void Info(string message, params object[] values); void Warn(string message, params object[] values); void Error(string message, params object[] values); void Fatal(string message, params object[] values); } and the following implementation: public class Log4netLogger : ILogger { private ILog _log; public Log4netLogger(Type type) { _log = LogManager.GetLogger(type); } public void Debug(string message, params object[] values) { _log.DebugFormat(message, values); } // other logging

Xml configuration or Configuration through code?

爷,独闯天下 提交于 2019-11-28 11:09:54
I personally like the option to configure StructureMap from C# code. From what I understand, one of the advantages of DI, is that we can easily swap in a new concrete instance. But, if the configuration is defined in code, then the concrete instances are hardcoded in the dll. So, practically, its as good as having hard coded the dependencies, right? I know, during testing it makes life easier... My point is, wouldnt it be better to use xml configuration instead? you want to plugin a new concrete instance? simply have your installer overwrite the structuremap.config file with the new one. So,