using System;
using Autofac;
using JumbleRef.Core.Models.ComponentModel;

namespace JumbleRef.Core.Services
{
    public interface IReactiveCacheFactory
    {
        IReactiveCacheService<TKey, TValue> Get<TKey, TValue>()
            where TKey : IEquatable<TKey>
            where TValue : IReactiveModel<TKey>;
    }

    public sealed class ReactiveCacheFactory : IReactiveCacheFactory, IService
    {
        private readonly ILifetimeScope mLifetimeScope;

        public ReactiveCacheFactory(ILifetimeScope lifetimeScope)
        {
            mLifetimeScope = lifetimeScope;
        }

        public IReactiveCacheService<TKey, TValue> Get<TKey, TValue>()
            where TKey : IEquatable<TKey>
            where TValue : IReactiveModel<TKey>
            => mLifetimeScope.Resolve<IReactiveCacheService<TKey, TValue>>();
    }
}
