Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
1.8 kB
15
Indexable
Never
//we might need to inject some dals here too
internal class AllSecurityProviders
    {
        private readonly IADSecurityProviderBll adSecurityProviderBll;
        private readonly IAPISecurityProviderBll apiSecurityProviderBll;
        private readonly ISocialProviderBll socialProviderBll;

        private readonly object activeProviderLock = new object();
        // This interface is inherited by all securityProviderBlls
        private ISecurityProvider activeSecurityProvider;

        public AllSecurityProviders(IADSecurityProviderBll adSecurityProviderBll, IAPISecurityProviderBll apiSecurityProviderBll, ISocialProviderBll socialProviderBll)
        {
            this.adSecurityProviderBll = adSecurityProviderBll;
            this.apiSecurityProviderBll = apiSecurityProviderBll;
            this.socialProviderBll = socialProviderBll;
        }


        public List<GroupDto> GetGroupsByProviderID(int userId, int providerType)
        {
            SwitchActiveProviderById(providerType);

            return activeSecurityProvider.GetGroupsByUserId(userId);
        }

        public void SwitchActiveProviderById(int providerType)
        {
            lock (activeProviderLock)
            {
                switch (providerType)
                {
                    case 1:
                        activeSecurityProvider = adSecurityProviderBll;
                        break;
                    case 2:
                        activeSecurityProvider = apiSecurityProviderBll;
                        break;
                    default:
                        throw new ArgumentException("SOMETHING WENT WRONG MY DUDE");
                }
            }
            
        }

    }