funq

Funq usage in ServiceStack

隐身守侯 提交于 2020-01-12 05:35:20
问题 How can I access Container instance out of controller? I have to use Container.Resolve in my class but how can I access Container instance? Is it singleton? Can I use new Container() or is there any chain like Funq.StaticContainer ? Thanks to Mythz for gist hint, a) or b) or c). I will use Mythz's solution, it is accepted by me but there are concerns for it's pattern ( ServiceLocator Pattern), you can check here for extra info. 回答1: There are a couple of ways to statically reference your

为什么我需要一个IoC容器而不是直接的DI代码? [关闭]

半腔热情 提交于 2020-01-06 15:40:05
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我一直在使用 依赖注入 (DI)一段时间,在构造函数,属性或方法中注入。 我从未觉得需要使用 控制反转 (IoC)容器。 但是,我读的越多,我觉得社区使用IoC容器的压力就越大。 我使用.NET容器,如 StructureMap , NInject , Unity 和 Funq 。 我仍然没有看到IoC容器如何使我的代码受益/改进。 我也害怕在工作中开始使用容器,因为我的许多同事都会看到他们不理解的代码。 他们中的许多人可能不愿意学习新技术。 请说服我需要使用IoC容器。 当我在工作中与开发人员交谈时,我将使用这些论点。 #1楼 我是一名康复的国际奥委会成瘾者。 这些天我发现很难证明在大多数情况下使用IOC来证明其合理性。 IOC容器牺牲了编译时检查,据说可以为您提供“简单”设置,复杂的生命周期管理以及在运行时动态发现依赖关系。 我发现编译时间检查的丢失以及由此导致的运行时间魔术/异常,在绝大多数情况下都不值得花里胡哨。 在大型企业应用程序中,他们可能很难跟踪正在发生的事情。 我不购买集中化论证,因为你可以非常容易地集中静态设置,为你的应用程序使用抽象工厂,并虔诚地将对象创建推迟到抽象工厂,即做适当的DI。 为什么不这样做静态无魔法DI: interface IServiceA { } interface

servicestack with funq - autowiring by convention

那年仲夏 提交于 2019-12-09 11:44:56
问题 I have a service which takes an IMyDependency in its constructor. IMyDependency, MyDependency and the service all live in the same assembly. MyDependency has a single, public, parameterless constructor. To my surprise, this did not work: container.RegisterAutoWired<IMyDependency>(); It throws a "System.NullReferenceException". It works if I do this: container.RegisterAutoWiredAs<MyDependency, IMyDependency>(); But then, so does this: container.RegisterAs<MyDependency, IMyDependency>(); So

Does Funq IoC Container support property injection?

*爱你&永不变心* 提交于 2019-12-06 02:05:34
问题 I'm looking for an IoC container to use in my Compact Framework application. Trying out Funq I noticed that I can't find a way to do Property Injection with it. I've looked through the discussion on the project's site and the unit tests for it, but I can't find any example of Property Injection. Does Funq support Property Injection? 回答1: Well wouldn't that generally go something like this? myContainer.Register<IUserRepository>(() => { var myRepository = new SomeUserRepository(); myRepository

ServiceStack - Dependency seem's to not be Injected?

南笙酒味 提交于 2019-12-05 02:48:35
问题 I have the following repository class: public class Repository<T> : IDisposable where T : new() { public IDbConnectionFactory DbFactory { get; set; } //Injected by IOC IDbConnection db; IDbConnection Db { get { return db ?? (db = DbFactory.Open()); } } public Repository() { Db.DropAndCreateTable<T>(); } public List<T> GetByIds(long[] ids) { return Db.Ids<T>(ids).ToList(); } } Then in my AppHost.Configure() . I register the dependency like so: container.Register<IDbConnectionFactory>(c => new

ServiceStack - Dependency seem's to not be Injected?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 17:04:13
I have the following repository class: public class Repository<T> : IDisposable where T : new() { public IDbConnectionFactory DbFactory { get; set; } //Injected by IOC IDbConnection db; IDbConnection Db { get { return db ?? (db = DbFactory.Open()); } } public Repository() { Db.DropAndCreateTable<T>(); } public List<T> GetByIds(long[] ids) { return Db.Ids<T>(ids).ToList(); } } Then in my AppHost.Configure() . I register the dependency like so: container.Register<IDbConnectionFactory>(c => new OrmLiteConnectionFactory(ConfigurationManager. ConnectionStrings["AppDb"].ConnectionString,

servicestack with funq - autowiring by convention

你说的曾经没有我的故事 提交于 2019-12-03 14:09:59
I have a service which takes an IMyDependency in its constructor. IMyDependency, MyDependency and the service all live in the same assembly. MyDependency has a single, public, parameterless constructor. To my surprise, this did not work: container.RegisterAutoWired<IMyDependency>(); It throws a "System.NullReferenceException". It works if I do this: container.RegisterAutoWiredAs<MyDependency, IMyDependency>(); But then, so does this: container.RegisterAs<MyDependency, IMyDependency>(); So what is the difference? If 'auto wiring' cannot find a concrete implementation, and it makes no difference

using RavenDB with ServiceStack

心已入冬 提交于 2019-12-03 13:36:29
问题 I read this post by Phillip Haydon about how to use NHibernate/RavenDB with ServiceStack. I don't see the point about getting the IDocumentStore and open new session every time i need something from the db like this: public class FooService : ServiceBase<Foo> { public IDocumentStore RavenStore{ get; set; } protected override object Run(ProductFind request) { using (var session = RavenStore.OpenSession()) { // Do Something... return new FooResponse{/*Object init*/}; } } } Why cant i just use

How to register multiple IDbConnectionFactory instances using Funq in ServiceStack.net

心不动则不痛 提交于 2019-11-28 04:45:19
How would you go about registering diferent IDbConnectionFactory instances in Funq and then access them directly within your services? Do named instances somehow come into play here? Is this the best approach to take when using different databases across services? Thanks! EDIT: An example ;). I could be way off here because I'm pretty new to IoC, but say for example I have 2 separate database connections that I'd like to inject. In ServiceStack, this is done in the Global.asax. container.Register<IDbConnectionFactory>(c => new OrmLiteConnectionFactory(@"Connection String 1",

How to register multiple IDbConnectionFactory instances using Funq in ServiceStack.net

你。 提交于 2019-11-27 05:25:44
问题 How would you go about registering diferent IDbConnectionFactory instances in Funq and then access them directly within your services? Do named instances somehow come into play here? Is this the best approach to take when using different databases across services? Thanks! EDIT: An example ;). I could be way off here because I'm pretty new to IoC, but say for example I have 2 separate database connections that I'd like to inject. In ServiceStack, this is done in the Global.asax. container