**Is the Lock necessary?** for WebApi HttpGet method that does DB referencing

Background:
My public method below GetMedia call the private class method GetMyDtoFromDataBase.

GetMyDtoFromDataBase uses an Entity Framework object, say LegacyDb : DbContext. LegacyDb inherits from System.Data.Entity.DbContext.
This inherited code is really bad code design, but i was wondering anyway if the Lock (because of this) is actually necessary.

This GetMedia is an HttpGet method of my MediaController object.

Questions:

Does the IIS application pool use (or can use) one single Controller object for multiple calls from different users/sessions?

In this instance would the application pool in IIS instatiate one MediaController object for multiple HttpGet GetMedia calls (like from different users/sessions)?

Or is a new MediaController object created for every call to this method GetMedia?

Is the Lock necessary?

        [HttpGet]
    public JsonCamelCaseResult GetMedia(string incidentName)
    {

        Dictionary<string, MediaObjects> mediaObjectDict = new Dictionary<string, MediaObjects>();

        lock (LockObject)
        {
            //GetMyDtoFromDataBase uses an Entity Framework object, say LegacyDb : DbContext
            //LegacyDb inherits from System.Data.Entity.DbContext
            //This HttpGet method is a public instance of my MediaController object.
            //Is this object used by the IIS application pool for multiple http get calls (from different sessions)?
            //Or is a new MediaController object created for every call to this method GetMedia?
            //Is the Lock necessary?

            MyDto[] myDtoArray = GetMyDtoFromDataBase(incidentName);

            if (myDtoArray != null && myDtoArray .Count() > 0)
            {
                //GET Media for "myTarget"
               string target = "myTarget";
                MediaObjects targetMediaObjects = CreateTarget(incidentName, myDtoArray , target);
                mediaObjectDict.Add(PascalTargetCase(target), targetMediaObjects);
            }
            else
            {
                return null;
            }

            return new JsonCamelCaseResult(mediaObjectDict, JsonRequestBehavior.AllowGet);
        }
    }

private MyDto[] GetMyDtoFromDataBase(LegacyDb db, string incidentName)
{
return db
.SourceMediaItems
.Select(x => new MyDto{ Source = x, Targets = x.Targets })
.ToArray();
}


Download is.the.lock.necessary.for.webapi.httpget.method.that.does.db.referencing.zip
Direct Link


Download


Download is.the.lock.necessary.for.webapi.httpget.method.that.does.db.referencing.zip
Mediafire


Download


Download is.the.lock.necessary.for.webapi.httpget.method.that.does.db.referencing.zip
Terafile


Download


Download is.the.lock.necessary.for.webapi.httpget.method.that.does.db.referencing.zip
Load.to


Download


Download is.the.lock.necessary.for.webapi.httpget.method.that.does.db.referencing.zip
Bayfiles


Download

Both comments and pings are currently closed.

Comments are closed.