structuremap

Mapper not initialized, When Use ProjectTo()

不问归期 提交于 2019-12-18 19:00:07
问题 I Use Automapper 5.2.0 In My Project. When I Use ProjectTo() In Code Get This Error: Mapper not initialized. Call Initialize with Appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance. Service Code public async Task

StructureMap IRegistrationConvention to register non default naming convention?

时光毁灭记忆、已成空白 提交于 2019-12-18 15:49:56
问题 I currently have a bunch of repositories like so IMyRepository IAnotherRepository They all inherit from IRepository (if this helps) How can I get structuremap to use an IRegistryConvention scanner to register my concrete types which are named SqlMyRepository SqlAnotherRepository 回答1: I had read that article but it didn't give me quite what I needed. The AddAllTypesOf registered all the concrete types against the IRepositoryInterface but instead I require that each concrete type is registered

Named Instances and a Default Instance in StructureMap?

老子叫甜甜 提交于 2019-12-18 13:16:05
问题 In my StructureMap bootstrapping code I'm using a custom convention to scan assemblies and add interface/implementation pairs to the object graph as named instances. Essentially I have some logic which checks configuration settings and drills down to this statement depending on various conditions: registry.For(interfaceType).Use(type) .Named(implementationName); This adds all of the named instances well enough. However, I'd also like to add a default instance in the event that an instance

SignalR + Dependency Injection Questions

左心房为你撑大大i 提交于 2019-12-18 12:12:30
问题 I am using SignalR in my MVC3 application, and since I have implemented StructureMap Dependency Injection on my controllers I would like to do the same in my hub, but I can't seem to get it working. Please tell me what's wrong with my codes below: SignalRSmDependencyResolver.cs public class SignalRSmDependencyResolver : DefaultDependencyResolver { private IContainer _container; public SignalRSmDependencyResolver(IContainer container) { _container = container; } public override object

SignalR + Dependency Injection Questions

泪湿孤枕 提交于 2019-12-18 12:11:37
问题 I am using SignalR in my MVC3 application, and since I have implemented StructureMap Dependency Injection on my controllers I would like to do the same in my hub, but I can't seem to get it working. Please tell me what's wrong with my codes below: SignalRSmDependencyResolver.cs public class SignalRSmDependencyResolver : DefaultDependencyResolver { private IContainer _container; public SignalRSmDependencyResolver(IContainer container) { _container = container; } public override object

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

☆樱花仙子☆ 提交于 2019-12-18 05:07:05
问题 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

How to map same interface to different ConcreteClasses with StructureMap?

我是研究僧i 提交于 2019-12-18 04:54:23
问题 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>

How to define a default constructor by code using StructureMap?

 ̄綄美尐妖づ 提交于 2019-12-17 19:33:26
问题 I can't figure out how to define the default constructor (when it exists overloads) for a type in StructureMap (version 2.5) by code. I want to get an instance of a service and the container has to inject a Linq2Sql data context instance into it. I wrote this in my 'bootstrapper' method : ForRequestedType<MyDataContext>().TheDefault.Is.OfConcreteType<MyDataContext>(); When I run my app, I got this error : StructureMap Exception Code: 202 No Default Instance defined for PluginFamily

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

核能气质少年 提交于 2019-12-17 17:39:25
问题 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

Configuring dependency injection with ASP.NET Web API 2.1

懵懂的女人 提交于 2019-12-17 15:25:21
问题 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