Back in 2016 I wrote a post called Analysis of Detective Fiction, which was both about how detective fiction tends to include analysis of detective fiction in it, and also where I give some of my own analysis of detective fiction.
To give a taste of the beginning:
Detective fiction is a curiously self-referential genre. Other genres may discuss themselves, for all I know, but this does seem to be a very common theme in detective stories. Sherlock Holmes talked about C. Auguste Dupin, Dorothy L. Sayers talked about the plot to one of the Father Brown stories in Busman’s Honeymoon, and both Agatha Christie and Sayers introduced successful female mystery writers as important characters into their stories.
As they say, read the whole thing.