Every writer puts a little of himself into his creations. And the case of Andrew Marlowe, whose ABC series “Castle” hit its 100th episode milestone April 1, is no exception.

The whodunit Castle revolves on the central relationship of mystery novelist Richard Castle and NYPD homicide detective Kate Beckett.

“The characters (of Castle and Beckett) are both reflections of me,” Marlowe admits. “There’s a lot of wish-projection in the Castle character, while in real life I’m a little more like Beckett — too serious for my own good.”

Either way, that’s a valuable personality mashup: “Castle” has beaten the odds more than once to stay on the air, and over five seasons has proved to be ABC’s ideal modern character procedural. Both standalone episodic and arcing screwball romance, Castle is actually a wish-fulfillment for many.

It shouldn’t have made it out of the gate, though. Marlowe had great credentials (screenwriter for Air Force One among others) but the idea for the show was shelved during the last Writers Guild strike. Eventually, it got a presentation order; producers used resources to instead make a 37-minute pilot they expanded once the show got picked up, says Barry Jossen, exec VP, studio creative and production, for ABC Entertainment Group. And in its first season, Castle struggled — the return of procedurals-with-romance hadn’t fully cycled back into fashion by then.

But “Castle” eventually beat the competition. “People were hungry for something new,” says Marlowe. “Straight procedurals had gotten darker and more sensationalistic. Being a fan of MASH, I knew you could deal with serious situations and yet have gallows humor, and that’s what I aspired to do.”

The show also synched with ABC’s lineup, slotted among such primetime sudsers as Desperate Housewives. “You have to diversify,” Jossen says. “To have the proper mix on our schedule, it was important to have a show that was closed-ended, but that had strong, relatable characters.”

Slowly, positive word-of-mouth built the show’s ratings, which also got a boost from star Nathan Fillion’s fan following, which tracked him from Housewives and — more significantly — the short-lived Firefly. He stokes fan flames via Twitter frequently.

“In the early years, Nathan’s fan base was crucial to us getting the word out,” acknowledges Marlowe. “We’ve grown from there and now have fans of Castle who aren’t Firefly fans.”

With its footing established, “Castle” branched out into tie-in books and international sales; it now airs in 220 territories. This summer it began second runs on TNT and has averaged 1.6 million viewers since then, says Michael Wright, president and head of programming for TNT, TBS and Turner Classic Movies.

“Our viewers love crime dramas with a sense of style and fun, brought to life by vivid characters with great chemistry,” he writes in an email interview. “It’s a perfect fit for our drama brand.”

Still, this is a character procedural for the new millennium, says Marlowe, proof of which may come from the fact that it has thus far survived what’s been called the “Moonlighting” curse: a will-they-or-won’t-they storyline that, when the characters actually become a couple, often deflates a show’s chemistry and spice.

“Castle’s” leads paired up in the fourth season, and so far the show is still going strong.

“It was a risk, but it’s a risk not to at that point,” says Marlowe. In 2012, he says, Castle and Beckett nursed a long-simmering affection for each other, and to keep them apart wouldn’t have made sense. “And relationships don’t always run smoothly, so there’s more for the characters and audience to see.”

Which, assuming “Castle” returns for a sixth season (no decision is likely to be made before May), audiences are likely to end up enjoying just as much as that first, tenuous season.

“I like to think I will get bored about four episodes before the audience does,” says Marlowe, who hasn’t yet hit that point. (It may help that he has a staff of eight writers and a fellow executive producer in David Amman, along with wife Terri Miller, who often writes scripts with her husband, to keep things fresh.)

Marlowe says: “’Castle’ reflects the different kinds of men in the world — long-suffering, supporting fathers, suitors — and he can kick ass and be deadly serious when he needs to. It’s great to find that all in one package, with a guy, and a show, that can pull it off.”

Behind the ‘Castle’ Walls

Favorite moments on the show from key team members