Skip to content

Commit

Permalink
Added overloads for IAbpStartupConfiguration.ReplaceService #983.
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalkan committed May 6, 2016
1 parent 223e4f8 commit 24c0b58
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Abp.Web.Api/WebApi/Controllers/AbpApiExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using System.Web.Http.ModelBinding;
using System.Web.Http.ValueProviders;

//TODO: This code need to be refactored.

namespace Abp.Web.Api.Description
{
public class AbpApiExplorer : ApiExplorer,IApiExplorer
Expand Down
1 change: 1 addition & 0 deletions src/Abp/Abp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<Compile Include="BackgroundJobs\NullBackgroundJobStore.cs" />
<Compile Include="Authorization\IPermissionDependency.cs" />
<Compile Include="Authorization\IPermissionDependencyContext.cs" />
<Compile Include="Configuration\Startup\AbpStartupConfigurationExtensions.cs" />
<Compile Include="Domain\Uow\ConnectionStringResolveArgs.cs" />
<Compile Include="Domain\Uow\DefaultConnectionStringResolver.cs" />
<Compile Include="Domain\Uow\IConnectionStringResolver.cs" />
Expand Down
43 changes: 43 additions & 0 deletions src/Abp/Configuration/Startup/AbpStartupConfigurationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using Abp.Dependency;

namespace Abp.Configuration.Startup
{
/// <summary>
/// Extension methods for <see cref="IAbpStartupConfiguration"/>.
/// </summary>
public static class AbpStartupConfigurationExtensions
{
/// <summary>
/// Used to replace a service type.
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="type">Type.</param>
/// <param name="impl">Implementation.</param>
/// <param name="lifeStyle">Life style.</param>
public static void ReplaceService(this IAbpStartupConfiguration configuration, Type type, Type impl, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton)
{
configuration.ReplaceService(type, () =>
{
configuration.IocManager.Register(type, impl, lifeStyle);
});
}

/// <summary>
/// Used to replace a service type.
/// </summary>
/// <typeparam name="TType">Type of the service.</typeparam>
/// <typeparam name="TImpl">Type of the implementation.</typeparam>
/// <param name="configuration">The configuration.</param>
/// <param name="lifeStyle">Life style.</param>
public static void ReplaceService<TType, TImpl>(this IAbpStartupConfiguration configuration, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton)
where TType : class
where TImpl : class, TType
{
configuration.ReplaceService(typeof(TType), () =>
{
configuration.IocManager.Register<TType, TImpl>(lifeStyle);
});
}
}
}
6 changes: 6 additions & 0 deletions src/Abp/Configuration/Startup/IAbpStartupConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public interface IAbpStartupConfiguration : IDictionaryBasedConfig
/// </summary>
INotificationConfiguration Notifications { get; }

/// <summary>
/// Used to replace a service type.
/// Given <see cref="replaceAction"/> should register an implementation for the <see cref="type"/>.
/// </summary>
/// <param name="type">The type to be replaced.</param>
/// <param name="replaceAction">Replace action.</param>
void ReplaceService(Type type, Action replaceAction);
}
}

0 comments on commit 24c0b58

Please sign in to comment.