Skip to content

Commit

Permalink
Merge pull request #193 from hadashiA/ku/expose-container-default
Browse files Browse the repository at this point in the history
Make sure IObjectResolver is registered by default
  • Loading branch information
hadashiA authored Apr 23, 2021
2 parents cb7f3da + 099e0eb commit 21897be
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
9 changes: 2 additions & 7 deletions VContainer/Assets/VContainer/Runtime/ContainerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace VContainer
public interface IContainerBuilder
{
object ApplicationOrigin { get; set; }
bool ContainerExposed { get; set; }

RegistrationBuilder Register(Type type, Lifetime lifetime);
RegistrationBuilder RegisterInstance(object instance);
Expand Down Expand Up @@ -46,7 +45,6 @@ public IScopedObjectResolver BuildScope()
public class ContainerBuilder : IContainerBuilder
{
public object ApplicationOrigin { get; set; }
public bool ContainerExposed { get; set; }

readonly IList<RegistrationBuilder> registrationBuilders = new List<RegistrationBuilder>();
List<Action<IObjectResolver>> buildCallbacks;
Expand Down Expand Up @@ -94,7 +92,7 @@ public virtual IObjectResolver Build()

protected (IReadOnlyList<IRegistration>, IReadOnlyList<(IRegistration, Action<IRegistration, IObjectResolver>)>) BuildRegistrations()
{
var registrations = new IRegistration[registrationBuilders.Count + (ContainerExposed ? 1 : 0)];
var registrations = new IRegistration[registrationBuilders.Count + 1];
var callbacks = new List<(IRegistration, Action<IRegistration, IObjectResolver>)>(registrations.Length);

#if VCONTAINER_PARALLEL_CONTAINER_BUILD
Expand Down Expand Up @@ -122,10 +120,7 @@ public virtual IObjectResolver Build()
}
}
#endif
if (ContainerExposed)
{
registrations[registrations.Length - 1] = ContainerRegistration.Default;
}
registrations[registrations.Length - 1] = ContainerRegistration.Default;

#if VCONTAINER_PARALLEL_CONTAINER_BUILD
Parallel.For(0, registrations.Count, i =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public static RegistrationBuilder RegisterFactory<TParam1, TParam2, TParam3, TPa
return registrationBuilder;
}

[Obsolete("IObjectResolver is registered by default. This method does nothing.")]
public static void RegisterContainer(this IContainerBuilder builder)
=> builder.ContainerExposed = true;
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ void InstallTo(IContainerBuilder builder)
extraInstallerStatic?.Install(builder);

builder.RegisterInstance<LifetimeScope>(this).AsSelf();
builder.RegisterContainer();
}

LifetimeScope GetRuntimeParent()
Expand Down

1 comment on commit 21897be

@vercel
Copy link

@vercel vercel bot commented on 21897be Apr 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.