unable to Calling GetService for each request in Core API

110 views Asked by At

With Microsoft.Practices.Unity, the GetService method of IDependencyResolver in Asp.Net webAPI is called for each request, where i can do the below(user specific resolving of container)

public UnityDependencyResolver(IUnityContainer container)
    {
string userKey = GetUserFromContext();

        if (_container != null)
        {
            if (_container.ContainsKey(userKey))
                _container[userKey] = container;
            else
                _container.Add(userKey, container);
        }
        else
        {
            _container = new Dictionary<string, IUnityContainer>();
            _container.Add(userKey, container);
        }

}

public object GetService(Type serviceType) {

            string userKey = GetUserKey();
            return _container[userKey].Resolve(serviceType);
       
    }

, i want to achieve the same in Core API. as i need this to show container data specific to user. now two user across global can see data of each other

Note: Cannot use default DI of Core API

Kindly help Thanks

tried below but no luck Custom unity Unity

0

There are 0 answers