-
Notifications
You must be signed in to change notification settings - Fork 38
How to upgrade to v4+ #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The latest has some breaking charges.
As for guidance, would you like to write about your experience updating?
You can help others and I can answer your questions along the way.
|
I have the same problem. I'm using |
Posting a unit test with failing code would be a good start
|
After upgrading the code no longer compiles, I have yet found a way to fix my code to build |
I'll add my Build issues (and solutions) one at a time on this thread for others to benefit from :-) Problem:Build error Solution:
|
Problem:Build Error Solutionsee this example or this example |
Problem:Build Error in BuilderStrategy derived classes: Solution:Adjust the signature of the |
Problem:Build Error in BuilderStrategy derived classes: Solution:Adjust the signature of the |
@rikrak |
Problem:Build Error in Builder Strategy derived class: Solution:The behaviour can be mimiced by something like: public static void AddResolverOverrides(ref BuilderContext ctx, ResolverOverride theOverride)
{
var newOverrides = ctx.Overrides;
newOverrides = newOverrides == null
? new ResolverOverride[]{theOverride}
: newOverrides.Concat(new[] {theOverride}).ToArray();
ctx.Overrides = newOverrides;
} Not entirely sure if this is the right way to go about it though... |
Problem:
I used the ParentContext of IBuilderContext to determine if anything in the build hierarchy was of a certain type. More specifically I was checking to see if a specific decorator class was being applied as part of the build. Solution:There is an |
Problem:There is a build warning: Solution:The InjectionFactory class has been deprecated. Injection factories are now registered directly with the container. Old code: New code: |
Be Aware:The public key token of the assembly has changed, so you may need to remove redundant assembly bindings from config files. For example:
Note:
|
ProblemI'm using this code to register my interfaces. but after the upgrade im getting the following error when resolving
|
@Ronosho Could you provide a bit more detail? The code you've provided doesn't compile for me. public class Tests
{
[TestMethod]
public void ShouldResolveAlternativeImplementationWhenUsingOverride()
{
// arrange
var target = new UnityContainer();
target
.RegisterType<IController, TheController>(new ContainerControlledLifetimeManager(), new InjectionConstructor(new AlternativeMessageProvider()))
.RegisterType<IMessageProvider, DefaultMessageProvider>()
;
// act
var actual = target.Resolve<IController>();
// assert
Assert.AreEqual(actual.GetMessage(), "Goodbye cruel world!");
}
}
public interface IController
{
string GetMessage();
}
public class TheController : IController
{
private readonly IMessageProvider _messageProvider;
public TheController(IMessageProvider messageProvider)
{
_messageProvider = messageProvider;
}
public string GetMessage()
{
return _messageProvider.CalculateMessage();
}
}
public interface IMessageProvider
{
string CalculateMessage();
}
class DefaultMessageProvider : IMessageProvider
{
public string CalculateMessage()
{
return "Hello World";
}
}
class AlternativeMessageProvider : IMessageProvider
{
public string CalculateMessage()
{
return "Goodbye cruel world!";
}
} |
Problem:Build Error in BuilderStrategy derived classes: Solution:Adjust the signature of the |
SolutionOk I managed to find out what I was doing wrong. |
Enabling Diagnostic extension should have helped you. It suppose to throw on injectors reuse. var container = new UnityContainer();
container.EnableDiagnostic();
... This extension method only works in DEBUG mode. |
@ENikS I did not realize we could do that, thanks. |
It changed in 5.9.0 |
The flow of issues seems to be drying out. Are you closer to finishing your upgrage? |
Think so. The Dependency Resollver bug I logged with the Container should
help. I'm hoping to complete the work tomorrow or the day after.
|
I've upgraded my solution today, and all looks good. This issue can be closed. |
I'm currently upgrading all my NuGet packages in our solution, I'm not familiar with Unity at all but upgrading gave some breaking issues, I solved some but this one I cannot seem to figure out.
The application tells me this 'InjectionFactory' is obsolete: 'InjectionFactory has been deprecated and will be removed in next release. Please use IUnityContainer.RegisterFactory(...) method instead.', I had several other RegisterType calls but replaced them all with RegisterFactory. But there seem to be no RegisterFactory for InjectionMembers.
Same problem with RegisterSingleTon
I'm currently suppressing it but I would rather fix it. |
You do not pass any injection members to injection factory.
|
Can any one implemented the below functionality in New Version. I am pretty new to Unity if you can guide how to achieve below behavior. Thanks Source https://mikaelkoskinen.net/post/unity-passing-constructor-parameters-to-resolve public class OrderedParametersOverride : ResolverOverride
} |
What happened to |
The number of changes in each Unity version is out of control. Many breaking changes with little to no documentation. |
Writing documentation is not my strongest skill. Would you like to help improving the docs? |
Description
I've upgraded my Unity.Abstractions references from v3.3.0 to v4.1.0 (along with other related unity packages) and there appears to be some breaking changes.
At the moment I'm not sure how to go about fixing my code; Is there any upgrade guidance available?
(I've spent the morning googling around, but not found anything so far, but I may be using the wrong search terms :-) )
The text was updated successfully, but these errors were encountered: