kreta/Kreta.WebApi/Naplo/Kreta.Naplo.WebApi/DependencyContainer.cs
2024-03-13 00:33:46 +01:00

72 lines
2.5 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Web;
using Kreta.Core.IoC;
using Kreta.Naplo.BusinessLogic.Propetries;
using Kreta.Naplo.Configuration.Kreta;
using Kreta.Naplo.Domain;
using Kreta.Naplo.Domain.V3.Enum;
using Kreta.Naplo.WebApi.V3.Common.Logic;
namespace Kreta.Naplo.WebApi
{
/// <summary>
/// Dependency resolver of webapi layer
/// </summary>
internal class DependencyContainer : Core.IoC.DependencyContainer
{
/// <summary>
/// Unknown user agent
/// </summary>
public const string UnknownUserAgent = "unknown_user_agent";
/// <summary>
/// Instance
/// </summary>
public static IDependencyResolver Instance
{
get
{
return GetResolver(WebApiLayer.Instance);
}
}
/// <summary>
/// Imported object resolved
/// </summary>
/// <param name="importedObject">Imported object</param>
protected override void OnImportedObjectResolved(object importedObject)
{
var service = importedObject as IService;
if (service != null)
{
service.Context = new ServiceContext
(
FelhasznaloLogic.GetInstituteCode(),
FelhasznaloLogic.GetInstituteUserId(),
FelhasznaloLogic.GetRoles().Contains(FelhasznaloSzerepkor.Tanar) ? new List<string>() { "Teacher" } : new List<string>(),
KretaNaploApiConfiguration.Instance.BaseUrl,
KretaNaploApiConfiguration.Instance.ApiKey,
HttpContext.Current?.Request?.UserAgent ?? UnknownUserAgent,
FelhasznaloLogic.GetSchoolYearId()
);
}
}
/// <summary>
/// Initialize
/// </summary>
protected override void Initialize()
{
#region V2
ImportFrom<Domain.V2.Service.ITanarService>(BusinessLogicLayer.Instance);
ImportFrom<Domain.V2.Service.IEnumService>(BusinessLogicLayer.Instance);
ImportFrom<Domain.V2.Service.ICommonService>(BusinessLogicLayer.Instance);
ImportFrom<Domain.V2.Service.IOraService>(BusinessLogicLayer.Instance);
ImportFrom<Domain.V2.Service.IErtekelesService>(BusinessLogicLayer.Instance);
ImportFrom<Domain.V2.Service.IIskolaorService>(BusinessLogicLayer.Instance);
#endregion
}
}
}