Skip to content

Commit

Permalink
Added new registration method
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelumnikov committed May 22, 2019
1 parent adf354b commit c3322f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 12 additions & 2 deletions microDI/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ public IReferencedObject RegisterAs<TInterface, TImplementation>(
c => instanceCreatorFunc(c), typeof(TImplementation), lifeCycle));
}

public IReferencedObject Register<TClass>(ILifeCyclePolicy lifeCycle)
{
RuntimeCheck.NotNull(lifeCycle, nameof(lifeCycle));

var registeringType = typeof(TClass);

return _registryService.Register(
registeringType, new RegisteredObject(null, registeringType, lifeCycle));
}

public IReferencedObject Register<TClass>(
Func<IContainer, TClass> instanceCreatorFunc, ILifeCyclePolicy lifeCycle)
{
Expand All @@ -82,12 +92,12 @@ public object Resolve(Type resolveType)

public TInterface Resolve<TInterface>()
{
return (TInterface)Resolve(typeof(TInterface));
return (TInterface) Resolve(typeof(TInterface));
}

public IReferencedObject GetReferencedType<TClass>()
{
return new ReferencedObject(_registryService.GetRegisteredObject(typeof(TClass)), _registryService);
}
}
}
}
13 changes: 12 additions & 1 deletion microDI/IContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public interface IContainer
/// <param name="lifeCycle">Life cycle of registered type.</param>
/// <see cref="IReferencedObject"/>
/// <see cref="ILifeCyclePolicy"/>
[NotNull] IReferencedObject RegisterAs<TInterface, TImplementation>([NotNull] ILifeCyclePolicy lifeCycle)
[NotNull] IReferencedObject RegisterAs<TInterface, TImplementation>(
[NotNull] ILifeCyclePolicy lifeCycle)
where TImplementation : TInterface;

/// <summary>
Expand All @@ -59,6 +60,16 @@ [NotNull] IReferencedObject RegisterAs<TInterface, TImplementation>(
[NotNull] ILifeCyclePolicy lifeCycle)
where TImplementation : TInterface;

/// <summary>
/// Register class and creator function to be used for instantiation with life
/// cycle.
/// </summary>
/// <typeparam name="TClass">Type of class to be registered</typeparam>
/// <param name="lifeCycle">Life cycle of registered type.</param>
/// <see cref="IReferencedObject"/>
/// <see cref="ILifeCyclePolicy"/>
[NotNull] IReferencedObject Register<TClass>([NotNull] ILifeCyclePolicy lifeCycle);

/// <summary>
/// Register class and creator function to be used for instantiation with life
/// cycle.
Expand Down

0 comments on commit c3322f6

Please sign in to comment.