unity-container

How can I use Unity with internal classes?

可紊 提交于 2019-12-01 19:21:34
问题 I have a Web API application and am using Unity for dependency injection. The application uses a library containing an Interface IDoStuff and a class that implements the interface: internal interface IDoStuff { void DoSomething(); } internal class DoStuff : IDoStuff { public void DoSomething() { // Do some stuff } } The library also has an public class that needs to do stuff: public class NeedToDoStuff { private IDoStuff doStuff; public NeedToDoStuff() { this.doStuff = new DoStuff(); }

How can I use Unity with internal classes?

六月ゝ 毕业季﹏ 提交于 2019-12-01 18:44:23
I have a Web API application and am using Unity for dependency injection. The application uses a library containing an Interface IDoStuff and a class that implements the interface: internal interface IDoStuff { void DoSomething(); } internal class DoStuff : IDoStuff { public void DoSomething() { // Do some stuff } } The library also has an public class that needs to do stuff: public class NeedToDoStuff { private IDoStuff doStuff; public NeedToDoStuff() { this.doStuff = new DoStuff(); } internal NeedToDoStuff(IDoStuff doStuff) { this.doStuff = doStuff; } void PleaseDoStuff() { doStuff

What should UnityContainer.Teardown method do?

不羁的心 提交于 2019-12-01 17:33:22
I would like to explicitly "release" object instance resolved by Unity. I hoped the Teardown method should be used exactly for this so I tried something like this: container.RegisterType(typeof(IMyType), typeof(MyType), new MyLifetimeManager()); var obj = container.Resolve<IMyType>(); ... container.Teardown(obj); MyLifetimeManager stores object instance in HttpContext.Current.Items . I expected that Teardown method will call RemoveValue on lifetime manager and release both MyType instance and lifetime manager instance. It doesn't work. First of all RemoveValue is not called and if I again call

Unity Container and Support for dotnet Core / netstandard [closed]

六眼飞鱼酱① 提交于 2019-12-01 16:44:50
So MS dropped (free sourced) Unity. Future of Unity The github repository appears inactive Unity on GitHub Anybody know what is going on with Unity ? Is there a IOC Dependency Injection tool for dotNet Core, if Unity is a dead end under dotnet core? EDIT: Still waiting on news about Unity. Alternatives for those searching : StructureMap , AutoFac or our selection , SimpleInjector It very active on GitHub. There are many downloads daily already ~1Million from Nuget alone. And its fast, very well documented, a nice API with good extensibility. Microsoft.Extensions.DependencyInjection would have

What should UnityContainer.Teardown method do?

廉价感情. 提交于 2019-12-01 16:19:28
问题 I would like to explicitly "release" object instance resolved by Unity. I hoped the Teardown method should be used exactly for this so I tried something like this: container.RegisterType(typeof(IMyType), typeof(MyType), new MyLifetimeManager()); var obj = container.Resolve<IMyType>(); ... container.Teardown(obj); MyLifetimeManager stores object instance in HttpContext.Current.Items . I expected that Teardown method will call RemoveValue on lifetime manager and release both MyType instance and

Silverlight: how to handle standard assemblies

本小妞迷上赌 提交于 2019-12-01 14:13:56
A usual Silverlight task: to make the size of xap-file smaller. There are a lot of hot-to-do manuals that explain how to make your application modular. But I didn't find anyone that explains how to make "modular" standard libraries. The biggest part of my xap-file (1.7Mb, when overall size is 1.8Mb) is occupied by standard assemblies: among them System.Windows.Controls.dll - 370Kb, System.Windows.Controls.Data.dll - 464Kb, etc... Could you please tell (or give a reference to manual) how to move these assemblies out of xap file? I could use prism/unity and load them dynamically, but in this

What should be injected as C'tor paramter under DI principles?

岁酱吖の 提交于 2019-12-01 12:59:57
I'm trying to understand which objects should be injected into an object and which should be created internally. If i have some List<int> (as data field) which holds infomation gathered during run time. it seems that i should init it in the c'tor instead of injecting it. but what about a hardware class which communicates through a COM port. do i let the HW class init the SerialPort or i inject it ? If the above mentioned SerialPort needs to be injected; what is the best way to do it ? do i create it manually : SerialPort port = new SerialPort(name, baud ...); HWClass hwClass = container.Reolve

Dependency Injection using Template 10

会有一股神秘感。 提交于 2019-12-01 12:39:04
I am trying to migrate some code from an old Windows 8.1 app that I had developed using Prism/Unity to a new UWP app using Template 10 and Unity. I have seen in the documentation for Template 10 here that you can override the ResolveForPage method. In my old Windows 8.1 app, there is a Resolve method in Prism that I would override like this: protected override object Resolve(Type type) { return Container.Resolve(type); } The signature for the Template 10 method is public override INavigable ResolveForPage(Page page, NavigationService navigationService) so I am not exactly sure how to convert

Inject require object depends on condition in constructor injection

♀尐吖头ヾ 提交于 2019-12-01 12:30:49
I have an interface public interface ITrnsitReport { List<UserDefinedType> GetTransitReportData (); } And it has only one implementation which is public class TransitReport : ITrnsitReport { private IValidateInput _inputValidation = null; private readonly ITransitRepository _transitRepo = null; public TransitReport (IValidateInput inputValidation, ITransitRepository transitRepo) { _inputValidation = inputValidation; _transitRepo = transitRepo; } public List<UserDefinedType> GetTransitReportData (string input1, string input2) { List<UserDefinedType> ppdcReportList = null; bool isValid =

Silverlight: how to handle standard assemblies

人盡茶涼 提交于 2019-12-01 12:16:31
问题 A usual Silverlight task: to make the size of xap-file smaller. There are a lot of hot-to-do manuals that explain how to make your application modular. But I didn't find anyone that explains how to make "modular" standard libraries. The biggest part of my xap-file (1.7Mb, when overall size is 1.8Mb) is occupied by standard assemblies: among them System.Windows.Controls.dll - 370Kb, System.Windows.Controls.Data.dll - 464Kb, etc... Could you please tell (or give a reference to manual) how to